}
protected function status_single( $args ) {
- $name = $args[0];
- $file = $this->parse_name( $name );
+ $plugins = $this->validate_plugin_names( $args );
+ if ( empty( $plugins ) )
+ exit(1);
- $details = $this->get_details( $file );
+ list( $plugin ) = $plugins;
- $status = $this->format_status( $this->get_status( $file ), 'long' );
+ $details = $this->get_details( $plugin->file );
- $version = $details[ 'Version' ];
+ $status = $this->format_status( $this->get_status( $plugin->file ), 'long' );
- if ( $this->has_update( $file ) )
+ $version = $details['Version'];
+
+ if ( $this->has_update( $plugin->file ) )
$version .= ' (%gUpdate available%n)';
echo WP_CLI::colorize( \WP_CLI\Utils\mustache_render( 'plugin-status.mustache', array(
- 'slug' => $name,
+ 'slug' => $plugin->name,
'status' => $status,
'version' => $version,
'name' => $details['Name'],
function activate( $args, $assoc_args = array() ) {
$network_wide = isset( $assoc_args['network'] );
- foreach ( $args as $name ) {
- $file = $this->parse_name( $name );
- if ( !$file )
- continue;
-
- activate_plugin( $file, '', $network_wide );
+ foreach ( $this->validate_plugin_names( $args ) as $plugin ) {
+ activate_plugin( $plugin->file, '', $network_wide );
- if ( $this->check_active( $file, $network_wide ) ) {
+ if ( $this->check_active( $plugin->file, $network_wide ) ) {
if ( $network_wide )
- WP_CLI::success( "Plugin '$name' network activated." );
+ WP_CLI::success( "Plugin '{$plugin->name}' network activated." );
else
- WP_CLI::success( "Plugin '$name' activated." );
+ WP_CLI::success( "Plugin '{$plugin->name}' activated." );
} else {
- WP_CLI::warning( 'Could not activate plugin: ' . $name );
+ WP_CLI::warning( "Could not activate the '{$plugin->name}' plugin." );
}
}
}
function deactivate( $args, $assoc_args = array() ) {
$network_wide = isset( $assoc_args['network'] );
- foreach ( $args as $name ) {
- $file = $this->parse_name( $name );
- if ( !$file )
- continue;
-
- deactivate_plugins( $file, false, $network_wide );
+ foreach ( $this->validate_plugin_names( $args ) as $plugin ) {
+ deactivate_plugins( $plugin->file, false, $network_wide );
- if ( ! $this->check_active( $file, $network_wide ) ) {
+ if ( ! $this->check_active( $plugin->file, $network_wide ) ) {
if ( $network_wide )
- WP_CLI::success( "Plugin '$name' network deactivated." );
+ WP_CLI::success( "Plugin '{$plugin->name}' network deactivated." );
else
- WP_CLI::success( "Plugin '$name' deactivated." );
+ WP_CLI::success( "Plugin '{$plugin->name}' deactivated." );
} else {
- WP_CLI::warning( 'Could not deactivate plugin: ' . $name );
+ WP_CLI::warning( "Could not deactivate the '{$plugin->name}' plugin." );
}
}
}
function toggle( $args, $assoc_args = array() ) {
$network_wide = isset( $assoc_args['network'] );
- foreach ( $args as $name ) {
- $file = $this->parse_name( $name );
- if ( !$file )
- continue;
-
- if ( $this->check_active( $file, $network_wide ) ) {
- $this->deactivate( array( $name ), $assoc_args );
+ foreach ( $this->validate_plugin_names( $args ) as $plugin ) {
+ if ( $this->check_active( $plugin->file, $network_wide ) ) {
+ $this->deactivate( array( $plugin->name ), $assoc_args );
} else {
- $this->activate( array( $name ), $assoc_args );
+ $this->activate( array( $plugin->name ), $assoc_args );
}
}
}
$path = untrailingslashit( WP_PLUGIN_DIR );
if ( !empty( $args ) ) {
- $file = $this->parse_name( $args[0] );
- if ( !$file )
+ $plugins = $this->validate_plugin_names( $args );
+ if ( empty( $plugins ) )
return;
- $path .= '/' . $file;
+ list( $plugin ) = $plugins;
+
+ $path .= '/' . $plugin->file;
if ( isset( $assoc_args['dir'] ) )
$path = dirname( $path );
*/
function update( $args, $assoc_args ) {
if ( isset( $assoc_args['version'] ) && 'dev' == $assoc_args['version'] ) {
- foreach ( $args as $arg ) {
- $this->_delete( $this->parse_name( $arg ) );
- $this->install( array( $arg ), $assoc_args );
+ foreach ( $this->validate_plugin_names( $args ) as $plugin ) {
+ $this->_delete( $plugin->file );
+ $this->install( array( $plugin->name ), $assoc_args );
}
} else {
parent::update_many( $args, $assoc_args );
}
protected function filter_item_list( $items, $args ) {
- $basenames = array_map( array( $this, 'parse_name' ), $args );
+ $basenames = wp_list_pluck( $this->validate_plugin_names( $args ), 'file' );
return \WP_CLI\Utils\pick_fields( $items, $basenames );
}
*
* wp plugin uninstall hello
*
- * @synopsis <plugin> [--no-delete]
+ * @synopsis <plugin>... [--no-delete]
*/
function uninstall( $args, $assoc_args = array() ) {
- $name = $args[0];
- $file = $this->parse_name( $name );
-
- if ( is_plugin_active( $file ) ) {
- WP_CLI::error( 'The plugin is active.' );
- }
-
- uninstall_plugin( $file );
+ foreach ( $this->validate_plugin_names( $args ) as $plugin ) {
+ if ( is_plugin_active( $plugin->file ) ) {
+ WP_CLI::warning( "The '{$plugin->name}' plugin is active." );
+ continue;
+ }
- if ( isset( $assoc_args['no-delete'] ) )
- return;
+ uninstall_plugin( $plugin->file );
- if ( $this->_delete( $file ) ) {
- WP_CLI::success( sprintf( "Uninstalled '%s' plugin.", $name ) );
+ if ( !isset( $assoc_args['no-delete'] ) && $this->_delete( $plugin->file ) ) {
+ WP_CLI::success( "Uninstalled '$plugin->name' plugin." );
+ }
}
}
-
/**
* Check if the plugin is installed
*
*
* wp plugin delete hello
*
- * @synopsis <plugin>
+ * @synopsis <plugin>...
*/
function delete( $args, $assoc_args = array() ) {
- $name = $args[0];
- $file = $this->parse_name( $name );
-
- if ( $this->_delete( $file ) ) {
- WP_CLI::success( sprintf( "Deleted '%s' plugin.", $name ) );
+ foreach ( $this->validate_plugin_names( $args ) as $plugin ) {
+ if ( $this->_delete( $plugin->file ) ) {
+ WP_CLI::success( "Deleted '{$plugin->name}' plugin." );
+ }
}
}
return $file;
}
- private function parse_name( $name ) {
- if ( $file = $this->_parse_name( $name ) ) {
- return $file;
- } else {
- WP_CLI::warning( "The plugin '$name' could not be found." );
- return false;
+ private function validate_plugin_names( $args ) {
+ $plugins = array();
+
+ foreach ( $args as $name ) {
+ $file = $this->_parse_name( $name );
+ if ( $file ) {
+ $plugins[] = (object) array(
+ 'name' => $name,
+ 'file' => $file
+ );
+ } else {
+ WP_CLI::warning( "The '$name' plugin could not be found." );
+ }
}
+
+ return $plugins;
}
/**