@@ -79,7 +79,7 @@ private function get_all_themes() {
7979
8080 if ( ! empty ( $ checked_themes ) ) {
8181 foreach ( $ checked_themes as $ slug => $ version ) {
82- $ theme_version_info [ $ slug ] = $ this ->is_theme_version_valid ( $ slug , $ version );
82+ $ theme_version_info [ $ slug ] = $ this ->is_theme_version_valid ( $ slug , $ version, $ all_update_info );
8383 }
8484 }
8585
@@ -184,14 +184,35 @@ private function get_all_themes() {
184184 }
185185
186186 /**
187- * Check if current version of the theme is higher than the one available at WP .org.
187+ * Check whether the installed version of a theme is not higher than the latest version on WordPress .org.
188188 *
189- * @param string $slug Theme slug.
190- * @param string $version Theme current version.
189+ * The update check already returns the latest version of every theme hosted on WordPress.org,
190+ * in `response` for themes with an update and in `no_update` for the others, so this does not
191+ * need a request per theme unless that information is missing.
191192 *
192- * @return bool|string
193+ * @param string $slug Theme slug.
194+ * @param string $version Installed theme version.
195+ * @param object|null $update_info Optional. Value of the `update_themes` site transient.
196+ *
197+ * @return bool|string Whether the version is valid, or an empty string for themes not on WordPress.org.
193198 */
194- protected function is_theme_version_valid ( $ slug , $ version ) {
199+ protected function is_theme_version_valid ( $ slug , $ version , $ update_info = null ) {
200+ if ( is_object ( $ update_info ) && isset ( $ update_info ->no_update ) ) {
201+ $ latest = null ;
202+ foreach ( [ 'response ' , 'no_update ' ] as $ key ) {
203+ $ themes = isset ( $ update_info ->$ key ) ? (array ) $ update_info ->$ key : [];
204+ // Entries are arrays in core, but filters can turn them into objects.
205+ $ theme = isset ( $ themes [ $ slug ] ) ? (array ) $ themes [ $ slug ] : [];
206+ if ( isset ( $ theme ['new_version ' ] ) ) {
207+ $ latest = (string ) $ theme ['new_version ' ];
208+ break ;
209+ }
210+ }
211+
212+ // Themes that are not on WordPress.org are not part of the update check response.
213+ return null === $ latest ? '' : ! version_compare ( $ version , $ latest , '> ' );
214+ }
215+
195216 /**
196217 * @var \WP_Error|object{name: string, slug: string, version: string, download_link: string} $theme_info
197218 */
0 commit comments