wp-cli / doctor-command

Diagnose problems within WordPress by running a series of checks for symptoms
MIT License
145 stars 22 forks source link

Fix divide-by-zero warning in plugin checks #167

Closed figureone closed 2 years ago

figureone commented 2 years ago

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 commented 2 years ago

Yeah I can work on that next week!

figureone commented 2 years ago

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 commented 2 years ago

Looks great, thanks!