Skip to content

Commit 12905ac

Browse files
Merge pull request #167 from figureone/fix-divide-by-zero
Fix divide-by-zero warning in plugin checks
2 parents 96ccc7c + 28b3afb commit 12905ac

File tree

5 files changed

+34
-4
lines changed

5 files changed

+34
-4
lines changed

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@
2929
"php": "5.6"
3030
},
3131
"process-timeout": 7200,
32-
"sort-packages": true
32+
"sort-packages": true,
33+
"allow-plugins": {
34+
"dealerdirect/phpcodesniffer-composer-installer": true
35+
}
3336
},
3437
"extra": {
3538
"branch-alias": {

features/check-plugin-active-count.feature

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,12 @@ Feature: Check whether a high number of plugins are activated
3333
Then STDOUT should be a table containing rows:
3434
| name | status | message |
3535
| plugin-active-count | warning | Number of active plugins (4) exceeds threshold (3). |
36+
37+
Scenario: Include network-enabled plugins in active plugin count
38+
Given a WP multisite installation
39+
And I run `wp plugin activate --network --all`
40+
41+
When I run `wp doctor check plugin-active-count`
42+
Then STDOUT should be a table containing rows:
43+
| name | status | message |
44+
| plugin-active-count | success | Number of active plugins (2) is less than threshold (80). |

features/check-plugin-deactivated.feature

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,21 @@ Feature: Check whether a high percentage of plugins are deactivated
4242
Then STDOUT should be a table containing rows:
4343
| name | status | message |
4444
| plugin-deactivated | warning | Greater than 60 percent of plugins are deactivated. |
45+
46+
Scenario: Gracefully handle no plugins installed
47+
Given a WP install
48+
And I run `wp plugin uninstall --all`
49+
50+
When I run `wp doctor check plugin-deactivated`
51+
Then STDOUT should be a table containing rows:
52+
| name | status | message |
53+
| plugin-deactivated | success | Less than 40 percent of plugins are deactivated. |
54+
55+
Scenario: Gracefully handle only network-enabled plugins installed and activated
56+
Given a WP multisite installation
57+
And I run `wp plugin activate --network --all`
58+
59+
When I run `wp doctor check plugin-deactivated`
60+
Then STDOUT should be a table containing rows:
61+
| name | status | message |
62+
| plugin-deactivated | success | Less than 40 percent of plugins are deactivated. |

inc/checks/class-plugin-active-count.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function run() {
2121

2222
$active = 0;
2323
foreach ( self::get_plugins() as $plugin ) {
24-
if ( 'active' === $plugin['status'] ) {
24+
if ( 'active' === $plugin['status'] || 'active-network' === $plugin['status'] ) {
2525
$active++;
2626
}
2727
}

inc/checks/class-plugin-deactivated.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ public function run() {
2222
$active = 0;
2323
$inactive = 0;
2424
foreach ( self::get_plugins() as $plugin ) {
25-
if ( 'active' === $plugin['status'] ) {
25+
if ( 'active' === $plugin['status'] || 'active-network' === $plugin['status'] ) {
2626
$active++;
2727
} elseif ( 'inactive' === $plugin['status'] ) {
2828
$inactive++;
2929
}
3030
}
3131

3232
$threshold = (int) $this->threshold_percentage;
33-
if ( ( $inactive / ( $inactive + $active ) ) > ( $threshold / 100 ) ) {
33+
if ( $inactive + $active > 0 && ( $inactive / ( $inactive + $active ) ) > ( $threshold / 100 ) ) {
3434
$this->set_status( 'warning' );
3535
$this->set_message( "Greater than {$threshold} percent of plugins are deactivated." );
3636
} else {

0 commit comments

Comments
 (0)