wp_supports_ai()
Checks whether AI features of WordPress can be used in the current environment.
The function serves as a general check point before starting AI capabilities: generating text, calling AI providers, building prompts, and other LLM scenarios.
By default, AI is considered enabled. You can disable it with the constant WP_AI_SUPPORT or via the filter wp_supports_ai.
If the AI functionality in a plugin or theme is optional, it’s better to check wp_supports_ai() before using it. This way, the code will respect the site-wide settings.
With WP_AI_SUPPORT = false support is hard-disabled (the filter won’t even get a chance).
With WP_AI_SUPPORT = true or if it’s not set, support can be modified via a hook.
Hooks from the function
Returns
true|false.
true— AI functions can be used in the current request.false— AI functions are disabled or unavailable.
Usage
wp_supports_ai(): bool;
Examples
#1 AI logic check before launch
The example shows how not to run AI code if AI support is disabled on the site.
if ( ! wp_supports_ai() ) {
return;
}
// You can safely run AI functionality here. #2 Disabling AI via a Constant
The constant is usually set in wp-config.php. After that, wp_supports_ai() will get false unless the value is changed by a filter.
define( 'WP_AI_SUPPORT', false );
#3 Disabling AI via a Filter
The example completely disables AI features on the site via the wp_supports_ai filter.
add_filter( 'wp_supports_ai', '__return_false' );
#4 Disable AI only in the admin panel
The example disables AI features only for requests in the admin panel.
add_filter( 'wp_supports_ai', 'my_disable_ai_in_admin' );
function my_disable_ai_in_admin( $is_enabled ) {
if ( is_admin() ) {
return false;
}
return $is_enabled;
}
Changelog
| Since 7.0.0 | Introduced. |
wp_supports_ai() wp supports ai code WP 7.0.2
function wp_supports_ai(): bool {
// Return early if AI is disabled by the current environment.
if ( defined( 'WP_AI_SUPPORT' ) && ! WP_AI_SUPPORT ) {
return false;
}
/**
* Filters whether the current request can use AI.
*
* This allows plugins and 3rd-party code to disable AI features on a per-request basis, or to even override explicit
* preferences defined by the site owner.
*
* @since 7.0.0
*
* @param bool $is_enabled Whether AI is available. Default to true.
*/
return (bool) apply_filters( 'wp_supports_ai', true );
}