Skip to content

Commit 8b5220d

Browse files
authored
Connectors: account for mu-plugins when resolving plugin.file status (#76994)
1 parent 3dc762d commit 8b5220d

2 files changed

Lines changed: 34 additions & 3 deletions

File tree

‎lib/compat/wordpress-7.0/class-wp-connector-registry.php‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
* env_var_name?: non-empty-string
2929
* },
3030
* plugin?: array{
31-
* file: non-empty-string
31+
* file: non-empty-string,
32+
* is_active?: callable(): bool
3233
* }
3334
* }
3435
*/
@@ -99,6 +100,8 @@ final class WP_Connector_Registry {
99100
*
100101
* @type string $file The plugin's main file path relative to the plugins
101102
* directory (e.g. 'akismet/akismet.php' or 'hello.php').
103+
* @type callable $is_active Optional callback to determine whether the plugin
104+
* is active. Receives no arguments and must return bool.
102105
* }
103106
* }
104107
* @return array|null The registered connector data on success, null on failure.
@@ -233,6 +236,20 @@ public function register( string $id, array $args ): ?array {
233236

234237
if ( ! empty( $args['plugin'] ) && is_array( $args['plugin'] ) && ! empty( $args['plugin']['file'] ) ) {
235238
$connector['plugin'] = array( 'file' => $args['plugin']['file'] );
239+
240+
if ( isset( $args['plugin']['is_active'] ) ) {
241+
if ( ! is_callable( $args['plugin']['is_active'] ) ) {
242+
_doing_it_wrong(
243+
__METHOD__,
244+
/* translators: %s: Connector ID. */
245+
sprintf( __( 'Connector "%s" plugin is_active must be callable.' ), esc_html( $id ) ),
246+
'7.0.0'
247+
);
248+
return null;
249+
}
250+
251+
$connector['plugin']['is_active'] = $args['plugin']['is_active'];
252+
}
236253
}
237254

238255
$this->registered_connectors[ $id ] = $connector;

‎lib/experimental/connectors/default-connectors.php‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,8 +525,22 @@ function _gutenberg_get_connector_script_module_data( array $data ): array {
525525

526526
if ( ! empty( $connector_data['plugin']['file'] ) ) {
527527
$file = $connector_data['plugin']['file'];
528-
$is_installed = file_exists( WP_PLUGIN_DIR . '/' . $file );
529-
$is_activated = $is_installed && is_plugin_active( $file );
528+
$is_installed = false;
529+
$is_activated = false;
530+
531+
if ( ! empty( $connector_data['plugin']['is_active'] ) && is_callable( $connector_data['plugin']['is_active'] ) ) {
532+
$is_activated = (bool) call_user_func( $connector_data['plugin']['is_active'] );
533+
}
534+
535+
if ( ! $is_activated ) {
536+
$is_activated = is_plugin_active( $file );
537+
}
538+
539+
if ( $is_activated ) {
540+
$is_installed = true;
541+
} else {
542+
$is_installed = file_exists( WP_PLUGIN_DIR . '/' . $file );
543+
}
530544

531545
$connector_out['plugin'] = array(
532546
'file' => $file,

0 commit comments

Comments
 (0)