Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 27 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ See the WordPress [Plugin Handbook](https://developer.wordpress.org/plugins/) de

### wp plugin activate

Activates a plugin.
Activates one or more plugins.

~~~
wp plugin activate [<plugin>...] [--all] [--network]
Expand Down Expand Up @@ -87,7 +87,7 @@ wp plugin activate [<plugin>...] [--all] [--network]

### wp plugin deactivate

Deactivates a plugin.
Deactivates one or more plugins.

~~~
wp plugin deactivate [<plugin>...] [--uninstall] [--all] [--network]
Expand Down Expand Up @@ -182,7 +182,7 @@ wp plugin get <plugin> [--field=<field>] [--fields=<fields>] [--format=<format>]

### wp plugin install

Installs a plugin.
Installs one or more plugins.

~~~
wp plugin install <plugin|zip|url>... [--version=<version>] [--force] [--activate] [--activate-network]
Expand All @@ -191,7 +191,7 @@ wp plugin install <plugin|zip|url>... [--version=<version>] [--force] [--activat
**OPTIONS**

<plugin|zip|url>...
A plugin slug, the path to a local zip file, or URL to a remote zip file.
One or more plugins to install. Accepts a plugin slug, the path to a local zip file, or a URL to a remote zip file.

[--version=<version>]
If set, get that particular version from wordpress.org, instead of the
Expand Down Expand Up @@ -434,11 +434,23 @@ search query.
**requires**: Plugin Minimum Requirements
**tested**: Plugin Tested Up To
**compatibility**: Plugin Compatible With
**rating**: Plugin Rating
**rating**: Plugin Rating in Percent and Total Number
**ratings**: Plugin Ratings for each star (1-5)
**num_ratings**: Number of Plugin Ratings
**homepage**: Plugin Author's Homepage
**description**: Plugin's Description
**short_description**: Plugin's Short Description
**sections**: Plugin Readme Sections: description, installation, FAQ, screenshots, other notes, and changelog
**downloaded**: Plugin Download Count
**last_updated**: Plugin's Last Update
**added**: Plugin's Date Added to wordpress.org Repository
**tags**: Plugin's Tags
**versions**: Plugin's Available Versions with D/L Link
**donate_link**: Plugin's Donation Link
**banners**: Plugin's Banner Image Link
**icons**: Plugin's Icon Image Link
**active_installs**: Plugin's Number of Active Installs
**contributors**: Plugin's List of Contributors

[--format=<format>]
Render output in a particular format.
Expand Down Expand Up @@ -541,15 +553,15 @@ inactive, then it will be activated.

### wp plugin uninstall

Uninstalls a plugin.
Uninstalls one or more plugins.

~~~
wp plugin uninstall <plugin>... [--deactivate] [--skip-delete]
wp plugin uninstall [<plugin>...] [--deactivate] [--skip-delete] [--all]
~~~

**OPTIONS**

<plugin>...
[<plugin>...]
One or more plugins to uninstall.

[--deactivate]
Expand All @@ -559,6 +571,9 @@ wp plugin uninstall <plugin>... [--deactivate] [--skip-delete]
If set, the plugin files will not be deleted. Only the uninstall procedure
will be run.

[--all]
If set, all plugins will be uninstalled.

**EXAMPLES**

$ wp plugin uninstall hello
Expand Down Expand Up @@ -721,13 +736,13 @@ wp theme activate <theme>

### wp theme delete

Deletes a theme.
Deletes one or more themes.

~~~
wp theme delete <theme>...
~~~

Removes the theme from the filesystem.
Removes the theme or themes from the filesystem.

**OPTIONS**

Expand Down Expand Up @@ -860,7 +875,7 @@ wp theme get <theme> [--field=<field>] [--fields=<fields>] [--format=<format>]

### wp theme install

Installs a theme.
Installs one or more themes.

~~~
wp theme install <theme|zip|url>... [--version=<version>] [--force] [--activate]
Expand All @@ -869,7 +884,7 @@ wp theme install <theme|zip|url>... [--version=<version>] [--force] [--activate]
**OPTIONS**

<theme|zip|url>...
A theme slug, the path to a local zip file, or URL to a remote zip file.
One or more themes to install. Accepts a theme slug, the path to a local zip file, or a URL to a remote zip file.

[--version=<version>]
If set, get that particular version from wordpress.org, instead of the
Expand Down
59 changes: 49 additions & 10 deletions features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ class FeatureContext extends BehatContext implements ClosuredContextInterface {
private $running_procs = array();

/**
* Array of variables available as {VARIABLE_NAME}. Some are always set: CORE_CONFIG_SETTINGS, SRC_DIR, CACHE_DIR, WP_VERSION-version-latest. Some are step-dependent:
* RUN_DIR, SUITE_CACHE_DIR, COMPOSER_LOCAL_REPOSITORY, PHAR_PATH. Scenarios can define their own variables using "Given save" steps. Variables are reset for each scenario.
* Array of variables available as {VARIABLE_NAME}. Some are always set: CORE_CONFIG_SETTINGS, SRC_DIR, CACHE_DIR, WP_VERSION-version-latest.
* Some are step-dependent: RUN_DIR, SUITE_CACHE_DIR, COMPOSER_LOCAL_REPOSITORY, PHAR_PATH. One is set on use: INVOKE_WP_CLI_WITH_PHP_ARGS-args.
* Scenarios can define their own variables using "Given save" steps. Variables are reset for each scenario.
*/
public $variables = array();

Expand Down Expand Up @@ -117,8 +118,9 @@ private static function get_process_env_variables() {
// Ensure we're using the expected `wp` binary
$bin_dir = getenv( 'WP_CLI_BIN_DIR' ) ?: realpath( __DIR__ . '/../../bin' );
$vendor_dir = realpath( __DIR__ . '/../../vendor/bin' );
$path_separator = Utils\is_windows() ? ';' : ':';
$env = array(
'PATH' => $bin_dir . ':' . $vendor_dir . ':' . getenv( 'PATH' ),
'PATH' => $bin_dir . $path_separator . $vendor_dir . $path_separator . getenv( 'PATH' ),
'BEHAT_RUN' => 1,
'HOME' => sys_get_temp_dir() . '/wp-cli-home',
);
Expand Down Expand Up @@ -328,20 +330,57 @@ public function getHookDefinitionResources() {
}

/**
* Replace {VARIABLE_NAME}. Note that variable names can only contain uppercase letters and underscores (no numbers).
* Replace standard {VARIABLE_NAME} variables and the special {INVOKE_WP_CLI_WITH_PHP_ARGS-args} and {WP_VERSION-version-latest} variables.
* Note that standard variable names can only contain uppercase letters, digits and underscores and cannot begin with a digit.
*/
public function replace_variables( $str ) {
$ret = preg_replace_callback( '/\{([A-Z_]+)\}/', array( $this, '_replace_var' ), $str );
if ( false !== strpos( $str, '{INVOKE_WP_CLI_WITH_PHP_ARGS-' ) ) {
$str = $this->replace_invoke_wp_cli_with_php_args( $str );
}
$str = preg_replace_callback( '/\{([A-Z_][A-Z_0-9]*)\}/', array( $this, 'replace_var' ), $str );
if ( false !== strpos( $str, '{WP_VERSION-' ) ) {
$ret = $this->_replace_wp_versions( $ret );
$str = $this->replace_wp_versions( $str );
}
return $str;
}

/**
* Substitute {INVOKE_WP_CLI_WITH_PHP_ARGS-args} variables.
*/
private function replace_invoke_wp_cli_with_php_args( $str ) {
static $phar_path = null, $shell_path = null;

if ( null === $phar_path ) {
$phar_path = false;
$phar_begin = '#!/usr/bin/env php';
$phar_begin_len = strlen( $phar_begin );
if ( ( $bin_dir = getenv( 'WP_CLI_BIN_DIR' ) ) && file_exists( $bin_dir . '/wp' ) && $phar_begin === file_get_contents( $bin_dir . '/wp', false, null, 0, $phar_begin_len ) ) {
$phar_path = $bin_dir . '/wp';
} else {
$src_dir = dirname( dirname( __DIR__ ) );
$bin_path = $src_dir . '/bin/wp';
$vendor_bin_path = $src_dir . '/vendor/bin/wp';
if ( file_exists( $bin_path ) && is_executable( $bin_path ) ) {
$shell_path = $bin_path;
} elseif ( file_exists( $vendor_bin_path ) && is_executable( $vendor_bin_path ) ) {
$shell_path = $vendor_bin_path;
} else {
$shell_path = 'wp';
}
}
}
return $ret;

$str = preg_replace_callback( '/{INVOKE_WP_CLI_WITH_PHP_ARGS-([^}]*)}/', function ( $matches ) use ( $phar_path, $shell_path ) {
return $phar_path ? "php {$matches[1]} {$phar_path}" : ( 'WP_CLI_PHP_ARGS=' . escapeshellarg( $matches[1] ) . ' ' . $shell_path );
}, $str );

return $str;
}

/**
* Replace variables callback.
*/
private function _replace_var( $matches ) {
private function replace_var( $matches ) {
$cmd = $matches[0];

foreach ( array_slice( $matches, 1 ) as $key ) {
Expand All @@ -352,9 +391,9 @@ private function _replace_var( $matches ) {
}

/**
* Substitute "{WP_VERSION-version-latest}" variables.
* Substitute {WP_VERSION-version-latest} variables.
*/
private function _replace_wp_versions( $str ) {
private function replace_wp_versions( $str ) {
static $wp_versions = null;
if ( null === $wp_versions ) {
$wp_versions = array();
Expand Down
4 changes: 3 additions & 1 deletion features/bootstrap/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace WP_CLI;

use WP_CLI\Utils;

/**
* Run a system process, and learn what happened.
*/
Expand Down Expand Up @@ -67,7 +69,7 @@ private function __construct() {}
public function run() {
$start_time = microtime( true );

$proc = proc_open( $this->command, self::$descriptors, $pipes, $this->cwd, $this->env );
$proc = Utils\proc_open_compat( $this->command, self::$descriptors, $pipes, $this->cwd, $this->env );

$stdout = stream_get_contents( $pipes[1] );
fclose( $pipes[1] );
Expand Down
Loading