Skip to content
Open
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
46 changes: 38 additions & 8 deletions features/theme.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
"""
2 changes: 1 addition & 1 deletion features/upgradables.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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 <type> list`
When I run `wp <type> 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 |
| <item> | inactive | available | <version> | {UPDATE_VERSION} | off |
Expand Down
19 changes: 16 additions & 3 deletions src/Theme_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class Theme_Command extends CommandWithUpgrade {
'version',
'update_version',
'auto_update',
'type',
];

public function __construct() {
Expand Down Expand Up @@ -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();
Expand All @@ -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;
}
Expand Down Expand Up @@ -915,6 +927,7 @@ public function delete( $args, $assoc_args ) {
* * version
* * update_version
* * auto_update
* * type
*
* These fields are optionally available:
*
Expand All @@ -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
*/
Expand Down
7 changes: 7 additions & 0 deletions src/WP_CLI/ParseThemeNameInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ),
Expand All @@ -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.
Expand Down