Skip to content

Conversation

@figureone
Copy link
Contributor

Aloha, in WordPress environments with no plugins installed, or multisite environments with only network-activated plugins, the plugin-deactivated check will throw a divide-by-zero warning:

$ wp doctor check plugin-deactivated
PHP Warning:  Division by zero in /home/ubuntu/.wp-cli/packages/vendor/wp-cli/doctor-command/inc/checks/class-plugin-deactivated.php on line 33
+--------------------+---------+--------------------------------------------------+
| name               | status  | message                                          |
+--------------------+---------+--------------------------------------------------+
| plugin-deactivated | success | Less than 40 percent of plugins are deactivated. |
+--------------------+---------+--------------------------------------------------+

Example plugin list:

$ wp plugin list
+----------------------------+----------------+-----------+---------+
| name                       | status         | update    | version |
+----------------------------+----------------+-----------+---------+
| advanced-custom-fields-pro | active-network | none      | 5.12.3  |
| classic-editor             | active-network | none      | 1.6.2   |
+----------------------------+----------------+-----------+---------+

This pull request explicitly checks that there are more than 0 active/inactive plugins, and also adds the active-network status to the count of activated plugins in the plugin-active-count and plugin-deactivated checks. See the following for a list of valid statuses:
https://developer.wordpress.org/cli/commands/plugin/list/

Thanks!

@figureone figureone requested a review from a team as a code owner August 18, 2022 20:50
Copy link
Member

@danielbachhuber danielbachhuber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the pull request, @figureone !

Can you add some Behat feature tests so we can make sure the bug doesn't crop up again?

@figureone
Copy link
Contributor Author

Yeah I can work on that next week!

@figureone
Copy link
Contributor Author

Got to it early!

$ composer behat -- features/check-plugin-deactivated.feature
$ composer behat -- features/check-plugin-active-count.feature

Tests should fail without the PR, and pass with it. Let me know if any tweaks are needed. Cheers

@danielbachhuber danielbachhuber added this to the 2.1.1 milestone Aug 19, 2022
@danielbachhuber
Copy link
Member

Looks great, thanks!

@danielbachhuber danielbachhuber merged commit 12905ac into wp-cli:main Aug 19, 2022
@figureone figureone deleted the fix-divide-by-zero branch August 25, 2022 19:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants