Make WordPress Core


Ignore:
Timestamp:
03/19/2026 01:55:45 PM (7 months ago)
Author:
SergeyBiryukov
Message:

AI: Introduce wp_supports_ai() function to control LLM-related features.

This includes a WP_AI_SUPPORT constant and a wp_supports_ai filter.

When false,

  • _wp_connectors_get_provider_settings() will return an empty array (short-circuiting the other functionality).
  • WP_AI_Client_Prompt_Builder() will short-circuit the construction with a WP_Error(). wp_ai_client_prompt() will still return an instance, to allow for fluidity to remain intact.

Priority: WP_AI_SUPPORT > add_filter( 'wp_supports_ai', ...) > (default: true)

Follow-up to [61943], [61749], [61943].

Props justlevine, westonruter, gziolo, flixos90, romainmrhenry, ahortin, chrismcelroyseo, SergeyBiryukov.
See #64706.

File:
1 edited

Legend:

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

    r61700 r62067  
    99
    1010use WordPress\AiClient\AiClient;
     11
     12/**
     13 * Returns whether AI features are supported in the current environment.
     14 *
     15 * @since 7.0.0
     16 *
     17 * @return bool Whether AI features are supported.
     18 */
     19function wp_supports_ai(): bool {
     20        $is_enabled = defined( 'WP_AI_SUPPORT' ) ? WP_AI_SUPPORT : true;
     21
     22        /**
     23         * Filters whether the current request should use AI.
     24         *
     25         * This allows plugins and 3rd-party code to disable AI features on a per-request basis, or to even override explicit
     26         * preferences defined by the site owner.
     27         *
     28         * @since 7.0.0
     29         *
     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.
     32         */
     33        return (bool) apply_filters( 'wp_supports_ai', $is_enabled );
     34}
    1135
    1236/**
Note: See TracChangeset for help on using the changeset viewer.