Skip to content

Commit

Permalink
Default $network_wide to boolean when activating plugins
Browse files Browse the repository at this point in the history
Since we were not defaulting to a boolean value, the $network_wide
variable was null, when the `--network` flag was omitted.

This causes type errors when activated plugins run their activation
hooks and they expect a boolean value for the $network_wide variable,
as illustrated in issue #348.
  • Loading branch information
raicem committed Jul 23, 2023
1 parent 5773bd6 commit 1179f2b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 21 additions & 0 deletions features/plugin-activate.feature
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,27 @@ Feature: Activate WordPress plugins
Plugin 'user-switching' activated.
"""

Scenario: Activating a plugin with no network wide option passes down correct types
Given a wp-content/plugins/example-plugin.php file:
"""
<?php
// Plugin Name: Example Plugin
function example_plugin_activate( bool $network_wide = false ) {
// Doesn't matter what we do here, we just need a function definition to check the type
return;
}
register_activation_hook( __FILE__, 'example_plugin_activate' );
"""

When I run `wp plugin activate example-plugin`
Then STDOUT should be:
"""
Plugin 'example-plugin' activated.
Success: Activated 1 of 1 plugins.
"""

Scenario: Not giving a slug on activate should throw an error unless --all given
When I try `wp plugin activate`
Then the return code should be 1
Expand Down
2 changes: 1 addition & 1 deletion src/Plugin_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ protected function get_all_items() {
* Success: Network activated 1 of 1 plugins.
*/
public function activate( $args, $assoc_args = array() ) {
$network_wide = Utils\get_flag_value( $assoc_args, 'network' );
$network_wide = Utils\get_flag_value( $assoc_args, 'network', false );
$all = Utils\get_flag_value( $assoc_args, 'all', false );
$all_exclude = Utils\get_flag_value( $assoc_args, 'exclude' );

Expand Down

0 comments on commit 1179f2b

Please sign in to comment.