diff --git a/features/plugin-install.feature b/features/plugin-install.feature index 2e10f027..36dfa55d 100644 --- a/features/plugin-install.feature +++ b/features/plugin-install.feature @@ -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: diff --git a/features/theme.feature b/features/theme.feature index ee136710..a01e2135 100644 --- a/features/theme.feature +++ b/features/theme.feature @@ -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: + """ + $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 ); } } @@ -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, '>' ); + } + /** * @var \WP_Error|object{name: string, slug: string, version: string, download_link: string} $theme_info */