-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Connectors: Add is_active callback support to plugin registration #77897
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f36ba9e
0b06523
d261e8d
50612ef
8f54b96
44c6825
3e64029
8588683
3d990ad
c9bb9ef
e62f202
8610c82
1d66f6f
9f687dc
8414c35
881e0c5
adc2600
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| https://github.com/WordPress/wordpress-develop/pull/11701 | ||
|
|
||
| * https://github.com/WordPress/gutenberg/pull/77897 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,9 +27,9 @@ | |
| * constant_name?: non-empty-string, | ||
| * env_var_name?: non-empty-string | ||
| * }, | ||
| * plugin?: array{ | ||
| * file: non-empty-string, | ||
| * is_active?: callable(): bool | ||
| * plugin: array{ | ||
| * file?: non-empty-string, | ||
| * is_active: callable(): bool | ||
| * } | ||
| * } | ||
| */ | ||
|
|
@@ -98,10 +98,12 @@ final class WP_Connector_Registry { | |
| * @type array $plugin { | ||
| * Optional. Plugin data for install/activate UI. | ||
| * | ||
| * @type string $file The plugin's main file path relative to the plugins | ||
| * directory (e.g. 'akismet/akismet.php' or 'hello.php'). | ||
| * @type string $file Optional. 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. | ||
|
westonruter marked this conversation as resolved.
|
||
| * Defaults to `__return_true`. | ||
| * } | ||
| * } | ||
| * @return array|null The registered connector data on success, null on failure. | ||
|
|
@@ -234,8 +236,12 @@ 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'] ); | ||
| $connector['plugin'] = array(); | ||
|
|
||
| if ( ! empty( $args['plugin'] ) && is_array( $args['plugin'] ) ) { | ||
| if ( ! empty( $args['plugin']['file'] ) ) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's possible here that |
||
| $connector['plugin']['file'] = $args['plugin']['file']; | ||
| } | ||
|
|
||
| if ( isset( $args['plugin']['is_active'] ) ) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we aligned with core and set $connector['plugin']['is_active'] == '__return_true', if a is_active was not passed?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see that in the phpdoc for and in the method: if ( ! isset( $connector['plugin']['is_active'] ) ) {
$connector['plugin']['is_active'] = '__return_true';
}So it does seem to make sense to update this to match what is in core. This aligns with what was done in WordPress/wordpress-develop@b3b40be. This would undo some things in the companion core PR: WordPress/wordpress-develop#11701 |
||
| if ( ! is_callable( $args['plugin']['is_active'] ) ) { | ||
|
|
@@ -252,6 +258,10 @@ public function register( string $id, array $args ): ?array { | |
| } | ||
| } | ||
|
|
||
| if ( ! isset( $connector['plugin']['is_active'] ) ) { | ||
| $connector['plugin']['is_active'] = '__return_true'; | ||
| } | ||
|
|
||
| $this->registered_connectors[ $id ] = $connector; | ||
| return $connector; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See WordPress/wordpress-develop#11701 (comment)