Skip to content

Commit ed5cd65

Browse files
authored
Merge pull request #253 from wp-cli/fix/251-activate-php-requirements
2 parents a89a413 + 5806561 commit ed5cd65

File tree

5 files changed

+55
-7
lines changed

5 files changed

+55
-7
lines changed

features/plugin-activate.feature

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,29 @@ Feature: Activate WordPress plugins
8080
"""
8181
Success: No plugins installed.
8282
"""
83+
84+
@require-wp-5.2
85+
Scenario: Activating a plugin that does not meet PHP minimum throws a warning
86+
Given a wp-content/plugins/high-requirements.php file:
87+
"""
88+
<?php
89+
/**
90+
* Plugin Name: High PHP Requirements
91+
* Description: This is meant to not activate because PHP version is too low.
92+
* Author: WP-CLI tests
93+
* Requires PHP: 99.99
94+
*/
95+
"""
96+
And I run `wp plugin deactivate --all`
97+
And I run `php -r 'echo PHP_VERSION;'`
98+
And save STDOUT as {PHP_VERSION}
99+
100+
When I try `wp plugin activate high-requirements`
101+
Then STDERR should contain:
102+
"""
103+
Failed to activate plugin. Current PHP version ({PHP_VERSION}) does not meet minimum requirements for High PHP Requirements. The plugin requires PHP 99.99.
104+
"""
105+
And STDOUT should not contain:
106+
"""
107+
1 out of 1
108+
"""

features/plugin.feature

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ Feature: Manage WordPress plugins
185185
Given a WP install
186186
And a wp-content/plugins/network-only.php file:
187187
"""
188+
<?php
188189
// Plugin Name: Example Plugin
189190
// Network: true
190191
"""
@@ -206,6 +207,7 @@ Feature: Manage WordPress plugins
206207
Given a WP multisite install
207208
And a wp-content/plugins/network-only.php file:
208209
"""
210+
<?php
209211
// Plugin Name: Example Plugin
210212
// Network: true
211213
"""
@@ -537,7 +539,7 @@ Feature: Manage WordPress plugins
537539
"""
538540
And the return code should be 0
539541

540-
@require-wp-47
542+
@require-wp-4.7
541543
Scenario: Plugin hidden by "all_plugins" filter
542544
Given a WP install
543545
And these installed and active plugins:

src/Plugin_AutoUpdates_Command.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ public function enable( $args, $assoc_args ) {
7878
$disabled_only = Utils\get_flag_value( $assoc_args, 'disabled-only', false );
7979

8080
$args = $this->check_optional_args_and_all( $args, $all );
81+
if ( ! $args ) {
82+
return;
83+
}
8184

8285
$plugins = $this->fetcher->get_many( $args );
8386
$auto_updates = get_site_option( static::SITE_OPTION );
@@ -152,6 +155,9 @@ public function disable( $args, $assoc_args ) {
152155
$enabled_only = Utils\get_flag_value( $assoc_args, 'enabled-only', false );
153156

154157
$args = $this->check_optional_args_and_all( $args, $all );
158+
if ( ! $args ) {
159+
return;
160+
}
155161

156162
$plugins = $this->fetcher->get_many( $args );
157163
$auto_updates = get_site_option( static::SITE_OPTION );

src/Plugin_Command.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,18 @@ public function activate( $args, $assoc_args = array() ) {
330330
deactivate_plugins( $plugin->file, false, false );
331331
}
332332

333-
activate_plugin( $plugin->file, '', $network_wide );
334-
335-
$this->active_output( $plugin->name, $plugin->file, $network_wide, 'activate' );
336-
$successes++;
333+
$result = activate_plugin( $plugin->file, '', $network_wide );
334+
335+
if ( is_wp_error( $result ) ) {
336+
$message = $result->get_error_message();
337+
$message = preg_replace( '/<a\s[^>]+>.*<\/a>/im', '', $message );
338+
$message = wp_strip_all_tags( $message );
339+
$message = str_replace( 'Error: ', '', $message );
340+
WP_CLI::warning( "Failed to activate plugin. {$message}" );
341+
} else {
342+
$this->active_output( $plugin->name, $plugin->file, $network_wide, 'activate' );
343+
$successes++;
344+
}
337345
}
338346

339347
if ( ! $this->chained_command ) {
@@ -877,7 +885,7 @@ public function uninstall( $args, $assoc_args = array() ) {
877885

878886
$all = Utils\get_flag_value( $assoc_args, 'all', false );
879887

880-
// Check if plugin names of --all is passed.
888+
// Check if plugin names or --all is passed.
881889
$args = $this->check_optional_args_and_all( $args, $all, 'uninstall' );
882890
if ( ! $args ) {
883891
return;
@@ -1005,7 +1013,7 @@ public function is_active( $args, $assoc_args = array() ) {
10051013
public function delete( $args, $assoc_args = array() ) {
10061014
$all = Utils\get_flag_value( $assoc_args, 'all', false );
10071015

1008-
// Check if plugin names of --all is passed.
1016+
// Check if plugin names or --all is passed.
10091017
$args = $this->check_optional_args_and_all( $args, $all, 'delete' );
10101018
if ( ! $args ) {
10111019
return;

src/Theme_AutoUpdates_Command.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ public function enable( $args, $assoc_args ) {
7878
$disabled_only = Utils\get_flag_value( $assoc_args, 'disabled-only', false );
7979

8080
$args = $this->check_optional_args_and_all( $args, $all );
81+
if ( ! $args ) {
82+
return;
83+
}
8184

8285
$themes = $this->fetcher->get_many( $args );
8386
$auto_updates = get_site_option( static::SITE_OPTION );
@@ -152,6 +155,9 @@ public function disable( $args, $assoc_args ) {
152155
$enabled_only = Utils\get_flag_value( $assoc_args, 'enabled-only', false );
153156

154157
$args = $this->check_optional_args_and_all( $args, $all );
158+
if ( ! $args ) {
159+
return;
160+
}
155161

156162
$themes = $this->fetcher->get_many( $args );
157163
$auto_updates = get_site_option( static::SITE_OPTION );

0 commit comments

Comments
 (0)