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/tests/phpunit/tests/ai-client/wpAiClientPromptBuilder.php

    r62037 r62067  
    24062406         * @ticket 64591
    24072407         */
     2408        public function test_is_supported_returns_false_when_ai_not_supported() {
     2409                add_filter( 'wp_supports_ai', '__return_false' );
     2410
     2411                $builder = new WP_AI_Client_Prompt_Builder( AiClient::defaultRegistry(), 'Test prompt' );
     2412
     2413                $this->assertFalse( $builder->is_supported() );
     2414        }
     2415
     2416        /**
     2417         * Tests that is_supported returns false when prevent prompt filter returns true.
     2418         *
     2419         * @ticket 64591
     2420         */
    24082421        public function test_is_supported_returns_false_when_filter_prevents_prompt() {
    24092422                add_filter( 'wp_ai_client_prevent_prompt', '__return_true' );
    … …  
    24132426                $this->assertFalse( $builder->is_supported() );
    24142427        }
    2415 
    24162428        /**
    24172429         * Tests that generate_result returns WP_Error when prevent prompt filter returns true.
Note: See TracChangeset for help on using the changeset viewer.