Make WordPress Core


Ignore:
Timestamp:
04/16/2026 07:37:31 AM (3 months ago)
Author:
gziolo
Message:

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: https://github.com/WordPress/wordpress-develop/pull/11295

Follow-up to [62067].

Props justlevine, westonruter, gziolo, mindctrl, adamsilverstein, johnjamesjacoby, ahortin, nilambar, ozgursar, audrasjb, jeffpaul.
Fixes #64706.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/ai-client.php

    r62067 r62239  
    1818 */
    1919function 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
     
    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
Note: See TracChangeset for help on using the changeset viewer.