Make WordPress Core

Changeset 62289


Ignore:
Timestamp:
04/30/2026 02:05:06 PM (7 weeks ago)
Author:
jorgefilipecosta
Message:

Connectors: Gate default setting auto-registration on is_active.

Update _wp_register_default_connector_settings() to register a connector's
default API key setting only when the connector's plugin.is_active callback
returns true.
Add tests covering the gate's branches: setting skipped when is_active
returns false, setting registered when it returns true.

Props jorgefilipecosta, gziolo, peterwilsoncc.
Fixes #65099.

Location:
trunk
Files:
1 added
1 edited

Legend:

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

    r62288 r62289  
    550550 */
    551551function _wp_register_default_connector_settings(): void {
    552     $ai_registry         = AiClient::defaultRegistry();
    553552    $registered_settings = get_registered_settings();
    554553
    555     foreach ( wp_get_connectors() as $connector_id => $connector_data ) {
     554    foreach ( wp_get_connectors() as $connector_data ) {
    556555        $auth = $connector_data['authentication'];
    557556        if ( 'api_key' !== $auth['method'] || empty( $auth['setting_name'] ) ) {
     
    564563        }
    565564
    566         // For AI providers, skip if the provider is not in the AI Client registry.
    567         if ( 'ai_provider' === $connector_data['type'] && ! $ai_registry->hasProvider( $connector_id ) ) {
     565        if ( ! isset( $connector_data['plugin']['is_active'] ) || ! is_callable( $connector_data['plugin']['is_active'] ) ) {
     566            continue;
     567        }
     568
     569        if ( ! call_user_func( $connector_data['plugin']['is_active'] ) ) {
    568570            continue;
    569571        }
Note: See TracChangeset for help on using the changeset viewer.