From 7773917a4871be06a44004e31710e070d2b2f95e Mon Sep 17 00:00:00 2001
From: Rishabh Gupta
Date: Tue, 6 Oct 2026 23:04:31 +0530
Subject: [PATCH 1/2] Themes: Prevent previewing incompatible themes from the
theme installer cards.
---
src/js/_enqueues/wp/theme.js | 15 +++++++++++++++
src/wp-admin/css/themes.css | 10 ++++++++++
src/wp-admin/theme-install.php | 4 +++-
3 files changed, 28 insertions(+), 1 deletion(-)
diff --git a/src/js/_enqueues/wp/theme.js b/src/js/_enqueues/wp/theme.js
index ff5d72ad2801e..896acb3f0c040 100644
--- a/src/js/_enqueues/wp/theme.js
+++ b/src/js/_enqueues/wp/theme.js
@@ -434,6 +434,16 @@ themes.view.Theme = wp.Backbone.View.extend({
if ( this.model.get( 'displayAuthor' ) ) {
this.$el.addClass( 'display-author' );
}
+
+ // Flags themes that cannot be previewed in the theme installer.
+ if ( themes.isInstall ) {
+ this.$el.toggleClass( 'no-preview', ! this.isPreviewable( this.model ) );
+ }
+ },
+
+ // Whether a theme is compatible with the current WordPress and PHP versions, and can be previewed.
+ isPreviewable: function( model ) {
+ return !! ( model.get( 'compatible_wp' ) && model.get( 'compatible_php' ) );
},
// Adds a class to the currently active theme
@@ -501,6 +511,11 @@ themes.view.Theme = wp.Backbone.View.extend({
return this.touchDrag = false;
}
+ // Themes that are incompatible with the current WordPress or PHP version can't be previewed.
+ if ( ! this.isPreviewable( this.model ) ) {
+ return;
+ }
+
// Allow direct link path to installing a theme.
if ( $( event.target ).not( '.install-theme-preview' ).parents( '.theme-actions' ).length ) {
return;
diff --git a/src/wp-admin/css/themes.css b/src/wp-admin/css/themes.css
index 5b71c223b6ce6..7f22a935f1d84 100644
--- a/src/wp-admin/css/themes.css
+++ b/src/wp-admin/css/themes.css
@@ -175,6 +175,16 @@ body.js .theme-browser.search-loading {
opacity: 0.4;
}
+/* Themes that cannot be previewed in the theme installer */
+.theme-browser .theme.no-preview {
+ cursor: default;
+}
+
+.theme-browser.rendered .theme.no-preview:hover .theme-screenshot img,
+.theme-browser.rendered .theme.no-preview.focus .theme-screenshot img {
+ opacity: 1;
+}
+
.theme-browser .theme .more-details {
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";
opacity: 0;
diff --git a/src/wp-admin/theme-install.php b/src/wp-admin/theme-install.php
index 8e6fc5d1eea2c..a23b92edf0d7b 100644
--- a/src/wp-admin/theme-install.php
+++ b/src/wp-admin/theme-install.php
@@ -390,7 +390,9 @@
<# } #>
-
+ <# if ( data.compatible_wp && data.compatible_php ) { #>
+
+ <# } #>
Date: Wed, 7 Oct 2026 00:03:33 +0530
Subject: [PATCH 2/2] Themes: Skip incompatible themes when navigating the
theme installer preview.
---
src/js/_enqueues/wp/theme.js | 48 +++++++++++++++++++++++++++---------
1 file changed, 36 insertions(+), 12 deletions(-)
diff --git a/src/js/_enqueues/wp/theme.js b/src/js/_enqueues/wp/theme.js
index 896acb3f0c040..669e577b6bbdb 100644
--- a/src/js/_enqueues/wp/theme.js
+++ b/src/js/_enqueues/wp/theme.js
@@ -446,6 +446,23 @@ themes.view.Theme = wp.Backbone.View.extend({
return !! ( model.get( 'compatible_wp' ) && model.get( 'compatible_php' ) );
},
+ // Gets the closest theme that can be previewed, before (-1) or after (1) the given one.
+ getAdjacentPreviewable: function( model, direction ) {
+ var collection = this.model.collection,
+ index = collection.indexOf( model ) + direction,
+ adjacent;
+
+ while ( index >= 0 && index < collection.length ) {
+ adjacent = collection.at( index );
+
+ if ( this.isPreviewable( adjacent ) ) {
+ return adjacent;
+ }
+
+ index += direction;
+ }
+ },
+
// Adds a class to the currently active theme
// and to the overlay in detailed view mode.
activeTheme: function() {
@@ -569,8 +586,8 @@ themes.view.Theme = wp.Backbone.View.extend({
current = self.current;
}
- // Get next theme model.
- self.current = self.model.collection.at( self.model.collection.indexOf( current ) + 1 );
+ // Get the next theme model that can be previewed.
+ self.current = self.getAdjacentPreviewable( current, 1 );
// If we have no more themes, bail.
if ( _.isUndefined( self.current ) ) {
@@ -601,12 +618,12 @@ themes.view.Theme = wp.Backbone.View.extend({
current = self.current;
}
- // Get previous theme model.
- self.current = self.model.collection.at( self.model.collection.indexOf( current ) - 1 );
+ // Get the previous theme model that can be previewed.
+ self.current = self.getAdjacentPreviewable( current, -1 );
// If we have no more themes, bail.
if ( _.isUndefined( self.current ) ) {
- return;
+ return self.current = current;
}
preview.model = self.current;
@@ -631,8 +648,8 @@ themes.view.Theme = wp.Backbone.View.extend({
previousThemeButton = $themeInstaller.find( '.previous-theme' ),
nextThemeButton = $themeInstaller.find( '.next-theme' );
- // Disable previous at the zero position.
- if ( 0 === this.model.collection.indexOf( current ) ) {
+ // Disable previous if there is no previous theme that can be previewed.
+ if ( _.isUndefined( this.getAdjacentPreviewable( current, -1 ) ) ) {
previousThemeButton
.addClass( 'disabled' )
.prop( 'disabled', true );
@@ -640,8 +657,8 @@ themes.view.Theme = wp.Backbone.View.extend({
nextThemeButton.trigger( 'focus' );
}
- // Disable next if the next model is undefined.
- if ( _.isUndefined( this.model.collection.at( this.model.collection.indexOf( current ) + 1 ) ) ) {
+ // Disable next if there is no next theme that can be previewed.
+ if ( _.isUndefined( this.getAdjacentPreviewable( current, 1 ) ) ) {
nextThemeButton
.addClass( 'disabled' )
.prop( 'disabled', true );
@@ -2075,6 +2092,13 @@ themes.RunInstaller = {
// Handles `theme` route event.
// Queries the API for the passed theme slug.
themes.router.on( 'route:preview', function( slug ) {
+ var theme = self.view.view.theme,
+ model = self.view.collection.findWhere( { 'slug': slug } );
+
+ // Bail if the requested theme is not in the collection or can't be previewed.
+ if ( theme && ( ! model || ! theme.isPreviewable( model ) ) ) {
+ return;
+ }
// Remove existing handlers.
if ( themes.preview ) {
@@ -2083,9 +2107,9 @@ themes.RunInstaller = {
}
// If the theme preview is active, set the current theme.
- if ( self.view.view.theme && self.view.view.theme.preview ) {
- self.view.view.theme.model = self.view.collection.findWhere( { 'slug': slug } );
- self.view.view.theme.preview();
+ if ( theme && theme.preview ) {
+ theme.model = model;
+ theme.preview();
} else {
// Select the theme by slug.