Skip to content

Commit

Permalink
Merge pull request #253 from wp-cli/fix/251-activate-php-requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
schlessera authored Sep 29, 2020
2 parents a89a413 + 5806561 commit ed5cd65
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 7 deletions.
26 changes: 26 additions & 0 deletions features/plugin-activate.feature
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,29 @@ Feature: Activate WordPress plugins
"""
Success: No plugins installed.
"""

@require-wp-5.2
Scenario: Activating a plugin that does not meet PHP minimum throws a warning
Given a wp-content/plugins/high-requirements.php file:
"""
<?php
/**
* Plugin Name: High PHP Requirements
* Description: This is meant to not activate because PHP version is too low.
* Author: WP-CLI tests
* Requires PHP: 99.99
*/
"""
And I run `wp plugin deactivate --all`
And I run `php -r 'echo PHP_VERSION;'`
And save STDOUT as {PHP_VERSION}

When I try `wp plugin activate high-requirements`
Then STDERR should contain:
"""
Failed to activate plugin. Current PHP version ({PHP_VERSION}) does not meet minimum requirements for High PHP Requirements. The plugin requires PHP 99.99.
"""
And STDOUT should not contain:
"""
1 out of 1
"""
4 changes: 3 additions & 1 deletion features/plugin.feature
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ Feature: Manage WordPress plugins
Given a WP install
And a wp-content/plugins/network-only.php file:
"""
<?php
// Plugin Name: Example Plugin
// Network: true
"""
Expand All @@ -206,6 +207,7 @@ Feature: Manage WordPress plugins
Given a WP multisite install
And a wp-content/plugins/network-only.php file:
"""
<?php
// Plugin Name: Example Plugin
// Network: true
"""
Expand Down Expand Up @@ -537,7 +539,7 @@ Feature: Manage WordPress plugins
"""
And the return code should be 0

@require-wp-47
@require-wp-4.7
Scenario: Plugin hidden by "all_plugins" filter
Given a WP install
And these installed and active plugins:
Expand Down
6 changes: 6 additions & 0 deletions src/Plugin_AutoUpdates_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ public function enable( $args, $assoc_args ) {
$disabled_only = Utils\get_flag_value( $assoc_args, 'disabled-only', false );

$args = $this->check_optional_args_and_all( $args, $all );
if ( ! $args ) {
return;
}

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

$args = $this->check_optional_args_and_all( $args, $all );
if ( ! $args ) {
return;
}

$plugins = $this->fetcher->get_many( $args );
$auto_updates = get_site_option( static::SITE_OPTION );
Expand Down
20 changes: 14 additions & 6 deletions src/Plugin_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,10 +330,18 @@ public function activate( $args, $assoc_args = array() ) {
deactivate_plugins( $plugin->file, false, false );
}

activate_plugin( $plugin->file, '', $network_wide );

$this->active_output( $plugin->name, $plugin->file, $network_wide, 'activate' );
$successes++;
$result = activate_plugin( $plugin->file, '', $network_wide );

if ( is_wp_error( $result ) ) {
$message = $result->get_error_message();
$message = preg_replace( '/<a\s[^>]+>.*<\/a>/im', '', $message );
$message = wp_strip_all_tags( $message );
$message = str_replace( 'Error: ', '', $message );
WP_CLI::warning( "Failed to activate plugin. {$message}" );
} else {
$this->active_output( $plugin->name, $plugin->file, $network_wide, 'activate' );
$successes++;
}
}

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

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

// Check if plugin names of --all is passed.
// Check if plugin names or --all is passed.
$args = $this->check_optional_args_and_all( $args, $all, 'uninstall' );
if ( ! $args ) {
return;
Expand Down Expand Up @@ -1005,7 +1013,7 @@ public function is_active( $args, $assoc_args = array() ) {
public function delete( $args, $assoc_args = array() ) {
$all = Utils\get_flag_value( $assoc_args, 'all', false );

// Check if plugin names of --all is passed.
// Check if plugin names or --all is passed.
$args = $this->check_optional_args_and_all( $args, $all, 'delete' );
if ( ! $args ) {
return;
Expand Down
6 changes: 6 additions & 0 deletions src/Theme_AutoUpdates_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ public function enable( $args, $assoc_args ) {
$disabled_only = Utils\get_flag_value( $assoc_args, 'disabled-only', false );

$args = $this->check_optional_args_and_all( $args, $all );
if ( ! $args ) {
return;
}

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

$args = $this->check_optional_args_and_all( $args, $all );
if ( ! $args ) {
return;
}

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

0 comments on commit ed5cd65

Please sign in to comment.