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/connectors/wpConnectorRegistry.php

    r62056 r62067  
    398398                $this->assertSame( $instance1, $instance2 );
    399399        }
     400
     401        /**
     402         * Test registration skips AI connectors when AI is not supported.
     403         */
     404        public function test_register_skips_when_ai_not_supported() {
     405                add_filter( 'wp_supports_ai', '__return_false' );
     406
     407                $this->registry->register( 'first', self::$default_args );
     408
     409                $all = $this->registry->get_all_registered();
     410                $this->assertCount( 0, $all );
     411        }
    400412}
Note: See TracChangeset for help on using the changeset viewer.