diff --git a/features/theme.feature b/features/theme.feature index f2ea9aa0..259f1f68 100644 --- a/features/theme.feature +++ b/features/theme.feature @@ -87,8 +87,8 @@ Feature: Manage WordPress themes When I run `wp theme list` Then STDOUT should be a table containing rows: - | name | status | update | version | update_version | auto_update | - | twentytwelve | inactive | available | 1.4 | {UPDATE_VERSION} | off | + | name | status | update | version | update_version | auto_update | type | + | twentytwelve | inactive | available | 1.4 | {UPDATE_VERSION} | off | classic | When I run `wp theme activate twentytwelve` Then STDOUT should not be empty @@ -105,8 +105,8 @@ Feature: Manage WordPress themes When I run `wp theme list` Then STDOUT should be a table containing rows: - | name | status | update | version | update_version | auto_update | - | twentytwelve | active | available | 1.5 | {UPDATE_VERSION} | off | + | name | status | update | version | update_version | auto_update | type | + | twentytwelve | active | available | 1.5 | {UPDATE_VERSION} | off | classic | When I try `wp theme update` Then STDERR should be: @@ -722,8 +722,8 @@ Feature: Manage WordPress themes When I run `wp theme list` Then STDOUT should be a table containing rows: - | name | status | update | version | update_version | auto_update | requires | requires_php | - | example | inactive | unavailable | 1.0.0 | 2.0.0 | off | 100 | 5.6 | + | name | status | update | version | update_version | auto_update | type | requires | requires_php | + | example | inactive | unavailable | 1.0.0 | 2.0.0 | off | classic | 100 | 5.6 | When I try `wp theme update example` Then STDERR should contain: @@ -765,11 +765,41 @@ Feature: Manage WordPress themes When I run `wp theme list` Then STDOUT should be a table containing rows: - | name | status | update | version | update_version | auto_update | requires | requires_php | - | example | inactive | unavailable | 1.0.0 | 2.0.0 | off | 3.7 | 100 | + | name | status | update | version | update_version | auto_update | type | requires | requires_php | + | example | inactive | unavailable | 1.0.0 | 2.0.0 | off | classic | 3.7 | 100 | When I try `wp theme update example` Then STDERR should contain: """ Warning: example: This update requires PHP version 100 """ + + @require-wp-5.9 + Scenario: Check theme type field for block themes + Given a WP install + + When I run `wp theme list --fields=name,type` + Then STDOUT should be a table containing rows: + | name | type | + | twentytwentyfour | block | + + When I run `wp theme get twentytwentyfour --field=type` + Then STDOUT should be: + """ + block + """ + + Scenario: Check theme type field for classic themes + Given a WP install + + When I run `wp theme install twentytwelve --force` + And I run `wp theme list --fields=name,type --name=twentytwelve` + Then STDOUT should be a table containing rows: + | name | type | + | twentytwelve | classic | + + When I run `wp theme get twentytwelve --field=type` + Then STDOUT should be: + """ + classic + """ diff --git a/features/upgradables.feature b/features/upgradables.feature index 278f1275..baa40639 100644 --- a/features/upgradables.feature +++ b/features/upgradables.feature @@ -58,7 +58,7 @@ Feature: Manage WordPress themes and plugins Then STDOUT should not be empty And save STDOUT as {UPDATE_VERSION} - When I run `wp list` + When I run `wp list --fields=name,status,update,version,update_version,auto_update` Then STDOUT should be a table containing rows: | name | status | update | version | update_version | auto_update | | | inactive | available | | {UPDATE_VERSION} | off | diff --git a/src/Theme_Command.php b/src/Theme_Command.php index 5ae8459f..5deaad98 100644 --- a/src/Theme_Command.php +++ b/src/Theme_Command.php @@ -63,6 +63,7 @@ class Theme_Command extends CommandWithUpgrade { 'version', 'update_version', 'auto_update', + 'type', ]; public function __construct() { @@ -587,6 +588,9 @@ public function install( $args, $assoc_args ) { * +---------+----------------+ */ public function get( $args, $assoc_args ) { + /** + * @var \WP_Theme $theme + */ $theme = $this->fetcher->get_check( $args[0] ); $errors = $theme->errors(); @@ -612,15 +616,23 @@ public function get( $args, $assoc_args ) { 'tags', 'theme_root', 'theme_root_uri', + 'type', ]; $theme_obj = new stdClass(); foreach ( $theme_vars as $var ) { + // @phpstan-ignore-next-line $theme_obj->$var = $theme->$var; } $theme_obj->status = $this->get_status( $theme ); $theme_obj->description = wordwrap( $theme_obj->description ); + // Determine theme type (block or classic). is_block_theme() was added in WP 5.9. + $theme_obj->type = 'classic'; + if ( method_exists( $theme, 'is_block_theme' ) && $theme->is_block_theme() ) { + $theme_obj->type = 'block'; + } + if ( empty( $assoc_args['fields'] ) ) { $assoc_args['fields'] = $theme_vars; } @@ -915,6 +927,7 @@ public function delete( $args, $assoc_args ) { * * version * * update_version * * auto_update + * * type * * These fields are optionally available: * @@ -927,9 +940,9 @@ public function delete( $args, $assoc_args ) { * * # List inactive themes. * $ wp theme list --status=inactive --format=csv - * name,status,update,version,update_version,auto_update - * twentyfourteen,inactive,none,3.8,,off - * twentysixteen,inactive,available,3.0,3.1,off + * name,status,update,version,update_version,auto_update,type + * twentyfourteen,inactive,none,3.8,,off,classic + * twentysixteen,inactive,available,3.0,3.1,off,classic * * @subcommand list */ diff --git a/src/WP_CLI/ParseThemeNameInput.php b/src/WP_CLI/ParseThemeNameInput.php index aa37e311..5a4def56 100644 --- a/src/WP_CLI/ParseThemeNameInput.php +++ b/src/WP_CLI/ParseThemeNameInput.php @@ -131,6 +131,12 @@ private function get_all_themes() { $requires_php = ! empty( $theme->get( 'RequiresPHP' ) ) ? $theme->get( 'RequiresPHP' ) : ''; } + // Determine theme type (block or classic). is_block_theme() was added in WP 5.9. + $theme_type = 'classic'; + if ( method_exists( $theme, 'is_block_theme' ) && $theme->is_block_theme() ) { + $theme_type = 'block'; + } + $items[ $stylesheet ] = [ 'name' => $key, 'status' => $this->get_status( $theme ), @@ -146,6 +152,7 @@ private function get_all_themes() { 'requires' => $requires, 'requires_php' => $requires_php, 'update_unavailable_reason' => isset( $update_unavailable_reason ) ? $update_unavailable_reason : '', + 'type' => $theme_type, ]; // Compare version and update information in theme list.