'version'
);
+ function __construct() {
+ parent::__construct();
+
+ $this->fetcher = new \WP_CLI\FetcherTheme( "The '%s' theme could not be found." );
+ }
+
protected function get_upgrader_class( $force ) {
return $force ? '\\WP_CLI\\DestructiveThemeUpgrader' : 'Theme_Upgrader';
}
}
protected function status_single( $args ) {
- $theme = $this->parse_name( $args[0] );
+ $theme = $this->fetcher->get_check( $args[0] );
$status = $this->format_status( $this->get_status( $theme ), 'long' );
* : The theme to activate.
*/
public function activate( $args = array() ) {
- $theme = $this->parse_name( $args[0] );
+ $theme = $this->fetcher->get_check( $args[0] );
switch_theme( $theme->get_template(), $theme->get_stylesheet() );
if ( empty( $args ) ) {
$path = WP_CONTENT_DIR . '/themes';
} else {
- $theme = $this->parse_name( $args[0] );
+ $theme = $this->fetcher->get_check( $args[0] );
$path = $theme->get_stylesheet_directory();
protected function filter_item_list( $items, $args ) {
$theme_files = array();
foreach ( $args as $arg ) {
- $theme_files[] = $this->parse_name( $arg )->get_stylesheet_directory();
+ $theme_files[] = $this->fetcher->get_check( $arg )->get_stylesheet_directory();
}
return \WP_CLI\Utils\pick_fields( $items, $theme_files );
* wp theme get twentytwelve --format=json
*/
public function get( $args, $assoc_args ) {
- $theme = $this->parse_name( $args[0] );
+ $theme = $this->fetcher->get_check( $args[0] );
// WP_Theme object employs magic getter, unfortunately
$theme_vars = array( 'name', 'title', 'version', 'parent_theme', 'template_dir', 'stylesheet_dir', 'template', 'stylesheet', 'screenshot', 'description', 'author', 'tags', 'theme_root', 'theme_root_uri',
* wp theme delete twentyeleven
*/
function delete( $args ) {
- foreach ( $this->validate_theme_names( $args ) as $theme ) {
+ foreach ( $this->fetcher->get_many( $args ) as $theme ) {
$theme_slug = $theme->get_stylesheet();
if ( $this->is_active_theme( $theme ) ) {
function _list( $_, $assoc_args ) {
parent::_list( $_, $assoc_args );
}
-
- /**
- * Parse the name of a plugin to a filename; check if it exists.
- *
- * @param string name
- * @return object
- */
- private function parse_name( $name ) {
- $theme = wp_get_theme( $name );
-
- if ( !$theme->exists() ) {
- WP_CLI::error( "The theme '$name' could not be found." );
- exit;
- }
-
- return $theme;
- }
-
- private function validate_theme_names( $args ) {
- $themes = array();
-
- foreach ( $args as $name ) {
- $theme = wp_get_theme( $name );
-
- if ( !$theme->exists() ) {
- WP_CLI::warning( "The '$name' theme could not be found." );
- } else {
- $themes[] = $theme;
- }
- }
-
- return $themes;
- }
}
WP_CLI::add_command( 'theme', 'Theme_Command' );