Make WordPress Core

Changeset 62306


Ignore:
Timestamp:
05/06/2026 05:52:48 PM (5 weeks ago)
Author:
desrosj
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.

Reviewed by desrosj.
Merges [62289] to the 7.0 branch.

Props jorgefilipecosta, gziolo, peterwilsoncc.
Fixes #65099.

Location:
branches/7.0
Files:
2 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/7.0

  • branches/7.0/src/wp-includes/connectors.php

    r62195 r62306  
    539539 */
    540540function _wp_register_default_connector_settings(): void {
    541     $ai_registry         = AiClient::defaultRegistry();
    542541    $registered_settings = get_registered_settings();
    543542
    544     foreach ( wp_get_connectors() as $connector_id => $connector_data ) {
     543    foreach ( wp_get_connectors() as $connector_data ) {
    545544        $auth = $connector_data['authentication'];
    546545        if ( 'api_key' !== $auth['method'] || empty( $auth['setting_name'] ) ) {
     
    553552        }
    554553
    555         // For AI providers, skip if the provider is not in the AI Client registry.
    556         if ( 'ai_provider' === $connector_data['type'] && ! $ai_registry->hasProvider( $connector_id ) ) {
     554        if ( ! isset( $connector_data['plugin']['is_active'] ) || ! is_callable( $connector_data['plugin']['is_active'] ) ) {
     555            continue;
     556        }
     557
     558        if ( ! call_user_func( $connector_data['plugin']['is_active'] ) ) {
    557559            continue;
    558560        }
Note: See TracChangeset for help on using the changeset viewer.