Skip to content

Commit aa8f9f2

Browse files
t-hamanoclaude
andcommitted
Connectors: Defer plugin.is_active check to connector retrieval.
Previously, `WP_Connector_Registry::register()` silently filled in `__return_true` when no `is_active` callback was provided, which made it impossible for consumers to distinguish "no callback supplied" from "callback always returns true." Defer the check to call sites instead, so the stored connector data reflects what was actually registered. Update `_wp_register_default_connector_settings()` and `_wp_connectors_get_connector_script_module_data()` to treat a missing callback as active, matching the documented `Defaults to __return_true` semantics. See #65020. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
1 parent b03a05e commit aa8f9f2

3 files changed

Lines changed: 10 additions & 10 deletions

File tree

src/wp-includes/class-wp-connector-registry.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,6 @@ public function register( string $id, array $args ): ?array {
270270
}
271271
}
272272

273-
if ( ! isset( $connector['plugin']['is_active'] ) ) {
274-
$connector['plugin']['is_active'] = '__return_true';
275-
}
276-
277273
$this->registered_connectors[ $id ] = $connector;
278274
return $connector;
279275
}

src/wp-includes/connectors.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -682,8 +682,13 @@ function _wp_connectors_get_connector_script_module_data( array $data ): array {
682682
);
683683

684684
if ( ! empty( $connector_data['plugin']['file'] ) ) {
685-
$file = $connector_data['plugin']['file'];
686-
$is_activated = (bool) call_user_func( $connector_data['plugin']['is_active'] );
685+
$file = $connector_data['plugin']['file'];
686+
if ( ! isset( $connector_data['plugin']['is_active'] ) ) {
687+
// Assume plugin has registered own connector and is therefore active.
688+
$is_activated = true;
689+
} else {
690+
$is_activated = (bool) call_user_func( $connector_data['plugin']['is_active'] );
691+
}
687692
$is_installed = $is_activated || file_exists( wp_normalize_path( WP_PLUGIN_DIR . '/' . $file ) );
688693

689694
$connector_out['plugin'] = array(

tests/phpunit/tests/connectors/wpConnectorRegistry.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -339,15 +339,14 @@ public function test_register_rejects_non_callable_plugin_is_active() {
339339
/**
340340
* @ticket 65020
341341
*/
342-
public function test_register_defaults_plugin_is_active_to_return_true() {
342+
public function test_register_omits_plugin_is_active_when_not_provided() {
343343
$args = self::$default_args;
344344
$args['plugin'] = array( 'file' => 'my-plugin/my-plugin.php' );
345345

346346
$result = $this->registry->register( 'default-callback', $args );
347347

348348
$this->assertIsArray( $result );
349-
$this->assertArrayHasKey( 'is_active', $result['plugin'] );
350-
$this->assertSame( '__return_true', $result['plugin']['is_active'] );
349+
$this->assertArrayNotHasKey( 'is_active', $result['plugin'] );
351350
}
352351

353352
/**
@@ -358,7 +357,7 @@ public function test_register_defaults_plugin_when_not_provided() {
358357

359358
$this->assertArrayHasKey( 'plugin', $result );
360359
$this->assertArrayNotHasKey( 'file', $result['plugin'] );
361-
$this->assertSame( '__return_true', $result['plugin']['is_active'] );
360+
$this->assertArrayNotHasKey( 'is_active', $result['plugin'] );
362361
}
363362

364363
/**

0 commit comments

Comments
 (0)