Skip to content

Commit 69a35b6

Browse files
committed
AI: Prevent wp_supports_ai filter from overriding the WP_AI_SUPPORT constant.
When `WP_AI_SUPPORT` is explicitly set to `false`, `wp_supports_ai()` now returns early before the filter runs. This ensures the site owner's explicit preference to disable AI cannot be overridden by a plugin via the `wp_supports_ai` filter. The filter default is now always `true`, since the constant check happens beforehand. Developed in: #11295 Follow-up to [62067]. Reviewed by justlevine, westonruter, adamsilverstein. Merges [62239] to the 7.0 branch. Props justlevine, westonruter, gziolo, mindctrl, adamsilverstein, johnjamesjacoby, ahortin, nilambar, ozgursar, audrasjb, jeffpaul. Fixes #64706. git-svn-id: https://develop.svn.wordpress.org/branches/7.0@62241 602fd350-edb4-49c9-b593-d223f7449a82
1 parent bc0a300 commit 69a35b6

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/wp-includes/ai-client.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,22 @@
1717
* @return bool Whether AI features are supported.
1818
*/
1919
function wp_supports_ai(): bool {
20-
$is_enabled = defined( 'WP_AI_SUPPORT' ) ? WP_AI_SUPPORT : true;
20+
// Return early if AI is disabled by the current environment.
21+
if ( defined( 'WP_AI_SUPPORT' ) && ! WP_AI_SUPPORT ) {
22+
return false;
23+
}
2124

2225
/**
23-
* Filters whether the current request should use AI.
26+
* Filters whether the current request can use AI.
2427
*
2528
* This allows plugins and 3rd-party code to disable AI features on a per-request basis, or to even override explicit
2629
* preferences defined by the site owner.
2730
*
2831
* @since 7.0.0
2932
*
30-
* @param bool $is_enabled Whether the current request should use AI. Default to WP_AI_SUPPORT constant, or true if
31-
* the constant is not defined.
33+
* @param bool $is_enabled Whether AI is available. Default to true.
3234
*/
33-
return (bool) apply_filters( 'wp_supports_ai', $is_enabled );
35+
return (bool) apply_filters( 'wp_supports_ai', true );
3436
}
3537

3638
/**

0 commit comments

Comments
 (0)