Skip to content

Commit bcf570c

Browse files
t-hamanoclaude
andcommitted
Connectors: Normalize plugin.is_active default at registration.
Move the missing-callback fallback from `_wp_connectors_get_connector_script_module_data()` into `WP_Connector_Registry::register()`, where the registered connector now always has `plugin.is_active` set to `__return_true` when omitted. This lets every consumer call the callback unconditionally instead of repeating an `isset()` guard, and tightens the PHPStan shape so `is_active` is no longer optional on the stored array. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 9cb5f08 commit bcf570c

2 files changed

Lines changed: 7 additions & 10 deletions

File tree

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
* },
4242
* plugin?: array{
4343
* file: non-empty-string,
44-
* is_active?: callable(): bool
44+
* is_active: callable(): bool
4545
* }
4646
* }
4747
*/
@@ -115,9 +115,7 @@ final class WP_Connector_Registry {
115115
* 'hello.php').
116116
* @type callable $is_active Optional callback to determine whether the plugin
117117
* is active. Receives no arguments and must return bool.
118-
* When omitted and `file` is provided, the connector is
119-
* treated as active on the assumption that the plugin
120-
* must be loaded in order to register itself.
118+
* Defaults to `__return_true`.
121119
* }
122120
* }
123121
* @return array|null The registered connector data on success, null on failure.
@@ -272,6 +270,10 @@ public function register( string $id, array $args ): ?array {
272270
}
273271
}
274272

273+
if ( ! isset( $connector['plugin']['is_active'] ) ) {
274+
$connector['plugin']['is_active'] = '__return_true';
275+
}
276+
275277
$this->registered_connectors[ $id ] = $connector;
276278
return $connector;
277279
}

src/wp-includes/connectors.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -687,12 +687,7 @@ function _wp_connectors_get_connector_script_module_data( array $data ): array {
687687

688688
if ( ! empty( $connector_data['plugin']['file'] ) ) {
689689
$file = $connector_data['plugin']['file'];
690-
if ( ! isset( $connector_data['plugin']['is_active'] ) ) {
691-
// Assume plugin has registered own connector and is therefore active.
692-
$is_activated = true;
693-
} else {
694-
$is_activated = (bool) call_user_func( $connector_data['plugin']['is_active'] );
695-
}
690+
$is_activated = (bool) call_user_func( $connector_data['plugin']['is_active'] );
696691
$is_installed = $is_activated || 0 === validate_plugin( $file );
697692

698693
$connector_out['plugin'] = array(

0 commit comments

Comments
 (0)