Skip to content

Commit 7523d4d

Browse files
committed
Connectors: Skip setting registration for inactive non-AI connector plugins
1 parent 341e216 commit 7523d4d

1 file changed

Lines changed: 27 additions & 2 deletions

File tree

src/wp-includes/connectors.php

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ function wp_is_connector_registered( string $id ): bool {
6060
*
6161
* @type string $file The plugin's main file path relative to the plugins
6262
* directory (e.g. 'my-plugin/my-plugin.php' or 'hello.php').
63+
* @type callable $is_active Optional callback to determine whether the plugin
64+
* is active. Receives no arguments and must return bool.
6365
* }
6466
* }
6567
* @phpstan-return ?array{
@@ -75,7 +77,8 @@ function wp_is_connector_registered( string $id ): bool {
7577
* env_var_name?: non-empty-string
7678
* },
7779
* plugin?: array{
78-
* file: non-empty-string
80+
* file: non-empty-string,
81+
* is_active?: callable(): bool
7982
* }
8083
* }
8184
*/
@@ -121,6 +124,8 @@ function wp_get_connector( string $id ): ?array {
121124
*
122125
* @type string $file The plugin's main file path relative to the plugins
123126
* directory (e.g. 'my-plugin/my-plugin.php' or 'hello.php').
127+
* @type callable $is_active Optional callback to determine whether the plugin
128+
* is active. Receives no arguments and must return bool.
124129
* }
125130
* }
126131
* }
@@ -137,7 +142,8 @@ function wp_get_connector( string $id ): ?array {
137142
* env_var_name?: non-empty-string
138143
* },
139144
* plugin?: array{
140-
* file: non-empty-string
145+
* file: non-empty-string,
146+
* is_active?: callable(): bool
141147
* }
142148
* }>
143149
*/
@@ -541,6 +547,10 @@ function _wp_register_default_connector_settings(): void {
541547
$ai_registry = AiClient::defaultRegistry();
542548
$registered_settings = get_registered_settings();
543549

550+
if ( ! function_exists( 'is_plugin_active' ) ) {
551+
require_once ABSPATH . 'wp-admin/includes/plugin.php';
552+
}
553+
544554
foreach ( wp_get_connectors() as $connector_id => $connector_data ) {
545555
$auth = $connector_data['authentication'];
546556
if ( 'api_key' !== $auth['method'] || empty( $auth['setting_name'] ) ) {
@@ -557,6 +567,21 @@ function _wp_register_default_connector_settings(): void {
557567
continue;
558568
}
559569

570+
// For non-AI connectors, skip if the owning plugin is not active.
571+
if ( 'ai_provider' !== $connector_data['type'] && ! empty( $connector_data['plugin'] ) ) {
572+
$is_active = false;
573+
574+
if ( ! empty( $connector_data['plugin']['is_active'] ) && is_callable( $connector_data['plugin']['is_active'] ) ) {
575+
$is_active = (bool) call_user_func( $connector_data['plugin']['is_active'] );
576+
} elseif ( ! empty( $connector_data['plugin']['file'] ) ) {
577+
$is_active = is_plugin_active( $connector_data['plugin']['file'] );
578+
}
579+
580+
if ( ! $is_active ) {
581+
continue;
582+
}
583+
}
584+
560585
register_setting(
561586
'connectors',
562587
$auth['setting_name'],

0 commit comments

Comments
 (0)