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
4 changes: 2 additions & 2 deletions features/plugin-install.feature
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,10 @@ Feature: Install WordPress plugins
Scenario: Can't install plugin that requires a newer version of PHP
Given a WP install

And I try `wp plugin install contact-form-7`
And I try `wp plugin install wp-mail-smtp`
Then STDERR should contain:
"""
Warning: contact-form-7: This plugin does not work with your version of PHP
Warning: wp-mail-smtp: This plugin does not work with your version of PHP
"""

And STDERR should contain:
Expand Down
38 changes: 38 additions & 0 deletions features/theme.feature
Original file line number Diff line number Diff line change
Expand Up @@ -909,3 +909,41 @@ Feature: Manage WordPress themes
| name | status |
| twentyeleven | active |
| twentytwelve | inactive |

# The update check only lists themes without an update in `no_update` since WordPress 5.5.
@require-wp-5.5
Scenario: Flag themes whose version is higher than the one on WordPress.org without a request per theme
Given a WP install
And I run `wp theme install twentytwelve --force`
And I run `sed -i.bak 's/^Version: .*/Version: 99.0/' wp-content/themes/twentytwelve/style.css`
And a wp-content/themes/my-local-theme/style.css file:
"""
/*
Theme Name: My Local Theme
Version: 1.0
*/
"""
And a wp-content/themes/my-local-theme/index.php file:
"""
<?php
"""
# The latest versions come from the update check, not from a theme information request per theme.
And that HTTP requests to api.wordpress.org/themes/info/ will respond with:
"""
HTTP/1.1 500 Internal Server Error
Content-Type: text/plain

Error
"""

When I run `wp theme list --fields=name,update,version`
Then STDOUT should be a table containing rows:
| name | update | version |
| twentytwelve | version higher than expected | 99.0 |
| my-local-theme | none | 1.0 |

When I try `wp theme update twentytwelve`
Then STDERR should contain:
"""
Warning: twentytwelve: version higher than expected.
"""
33 changes: 27 additions & 6 deletions src/WP_CLI/ParseThemeNameInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private function get_all_themes() {

if ( ! empty( $checked_themes ) ) {
foreach ( $checked_themes as $slug => $version ) {
$theme_version_info[ $slug ] = $this->is_theme_version_valid( $slug, $version );
$theme_version_info[ $slug ] = $this->is_theme_version_valid( $slug, $version, $all_update_info );
}
}

Expand Down Expand Up @@ -184,14 +184,35 @@ private function get_all_themes() {
}

/**
* Check if current version of the theme is higher than the one available at WP.org.
* Check whether the installed version of a theme is not higher than the latest version on WordPress.org.
*
* @param string $slug Theme slug.
* @param string $version Theme current version.
* The update check already returns the latest version of every theme hosted on WordPress.org,
* in `response` for themes with an update and in `no_update` for the others, so this does not
* need a request per theme unless that information is missing.
*
* @return bool|string
* @param string $slug Theme slug.
* @param string $version Installed theme version.
* @param object|null $update_info Optional. Value of the `update_themes` site transient.
*
* @return bool|string Whether the version is valid, or an empty string for themes not on WordPress.org.
*/
protected function is_theme_version_valid( $slug, $version ) {
protected function is_theme_version_valid( $slug, $version, $update_info = null ) {
if ( is_object( $update_info ) && isset( $update_info->no_update ) ) {
$latest = null;
foreach ( [ 'response', 'no_update' ] as $key ) {
$themes = isset( $update_info->$key ) ? (array) $update_info->$key : [];
// Entries are arrays in core, but filters can turn them into objects.
$theme = isset( $themes[ $slug ] ) ? (array) $themes[ $slug ] : [];
if ( isset( $theme['new_version'] ) ) {
$latest = (string) $theme['new_version'];
break;
}
}

// Themes that are not on WordPress.org are not part of the update check response.
return null === $latest ? '' : ! version_compare( $version, $latest, '>' );
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

/**
* @var \WP_Error|object{name: string, slug: string, version: string, download_link: string} $theme_info
*/
Expand Down
Loading