Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/wp-includes/class-wp-connector-registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
* env_var_name?: non-empty-string
* },
* plugin?: array{
* file: non-empty-string
* file: non-empty-string,
* is_active?: callable(): bool
* }
* }
*/
Expand Down Expand Up @@ -111,6 +112,8 @@ final class WP_Connector_Registry {
*
* @type string $file The plugin's main file path relative to the plugins
* directory (e.g. 'my-plugin/my-plugin.php' or 'hello.php').
* @type callable $is_active Optional callback to determine whether the plugin
* is active. Receives no arguments and must return bool.
* }
* }
* @return array|null The registered connector data on success, null on failure.
Expand Down Expand Up @@ -245,6 +248,20 @@ public function register( string $id, array $args ): ?array {

if ( ! empty( $args['plugin'] ) && is_array( $args['plugin'] ) && ! empty( $args['plugin']['file'] ) ) {
$connector['plugin'] = array( 'file' => $args['plugin']['file'] );

if ( isset( $args['plugin']['is_active'] ) ) {
if ( ! is_callable( $args['plugin']['is_active'] ) ) {
_doing_it_wrong(
__METHOD__,
/* translators: %s: Connector ID. */
sprintf( __( 'Connector "%s" plugin is_active must be callable.' ), esc_html( $id ) ),
'7.0.0'
);
return null;
}

$connector['plugin']['is_active'] = $args['plugin']['is_active'];
}
}

$this->registered_connectors[ $id ] = $connector;
Expand Down
18 changes: 16 additions & 2 deletions src/wp-includes/connectors.php
Original file line number Diff line number Diff line change
Expand Up @@ -674,8 +674,22 @@ function _wp_connectors_get_connector_script_module_data( array $data ): array {

if ( ! empty( $connector_data['plugin']['file'] ) ) {
$file = $connector_data['plugin']['file'];
$is_installed = file_exists( wp_normalize_path( WP_PLUGIN_DIR . '/' . $file ) );
$is_activated = $is_installed && is_plugin_active( $file );
$is_installed = false;
$is_activated = false;

if ( ! empty( $connector_data['plugin']['is_active'] ) && is_callable( $connector_data['plugin']['is_active'] ) ) {
$is_activated = (bool) call_user_func( $connector_data['plugin']['is_active'] );
}

if ( ! $is_activated ) {
$is_activated = is_plugin_active( $file );
}

if ( $is_activated ) {
$is_installed = true;
} else {
$is_installed = file_exists( WP_PLUGIN_DIR . '/' . $file );
}

$connector_out['plugin'] = array(
'file' => $file,
Expand Down
Loading