WPBP / WordPress-Plugin-Boilerplate-Powered

Wordpress Plugin Boilerplate but Powered with examples and a generator!
https://wpbp.github.io/
GNU General Public License v3.0
791 stars 114 forks source link

[BUG] Activation hook wrong argument type #221

Closed LucasDemea closed 2 years ago

LucasDemea commented 2 years ago

Describe the bug When activate the plugin using wp cli, an error occurs indicating that a wrong argument type was passed to the activate function.

To Reproduce

  1. Install plugin
  2. Activate plugin using wp-cli

Expected behavior The plugin activates without throwing any error

Additional context

PHP Fatal error:  Uncaught TypeError: Argument 1 passed to My_Plugin\Backend\ActDeact::activate() must be of the type bool, null given, called in /var/www/html/wp-includes/class-wp-hook.php on line 307 and defined in /var/www/html/wp-content/plugins/my-plugin/backend/ActDeact.php:62
Stack trace:
#0 /var/www/html/wp-includes/class-wp-hook.php(307): My_Plugin\Backend\ActDeact::activate(NULL)
#1 /var/www/html/wp-includes/class-wp-hook.php(331): WP_Hook->apply_filters('', Array)
#2 /var/www/html/wp-includes/plugin.php(476): WP_Hook->do_action(Array)
#3 /var/www/html/wp-admin/includes/plugin.php(691): do_action('activate_strada...', NULL)
#4 phar:///usr/local/bin/wp/vendor/wp-cli/extension-command/src/Plugin_Command.php(347): activate_plugin('my-plugin/s...', '', NULL)
#5 [internal function]: Plugin_Command->activate(Array, Array)
#6 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Dispatcher/CommandFactory.php(100): call_user_func(Array, Array, Array)
#7 [internal function]: WP_CLI\Dispatcher\CommandFactory in /var/www/html/wp-content/plugins/my-plugin/backend/ActDeact.php on line 62

What I found It seems that in some cases a null value is passed to the activation hook. Therefore, the activate function shouldn't limit its argument type to boolean.