diff --git a/src/wp-admin/css/wp-admin.css b/src/wp-admin/css/wp-admin.css
index 698c5ef9f0..5ff644d69d 100644
--- a/src/wp-admin/css/wp-admin.css
+++ b/src/wp-admin/css/wp-admin.css
@@ -6454,7 +6454,7 @@ span.imgedit-scale-warn {
background: #fff;
}
-.theme-browser .theme:hover .theme-screenshot img {
+.theme-browser.rendered .theme:hover .theme-screenshot img {
opacity: 0.4;
}
@@ -6477,7 +6477,7 @@ span.imgedit-scale-warn {
transition: opacity 0.1s ease-in-out;
}
-.theme-browser .theme:hover .more-details {
+.theme-browser.rendered .theme:hover .more-details {
opacity: 1;
}
diff --git a/src/wp-admin/includes/theme.php b/src/wp-admin/includes/theme.php
index 618ad896b3..9ed912c9ec 100644
--- a/src/wp-admin/includes/theme.php
+++ b/src/wp-admin/includes/theme.php
@@ -378,9 +378,11 @@ function themes_api( $action, $args = null ) {
* @return array An associative array of theme data, sorted by name.
*/
function wp_prepare_themes_for_js( $themes = null ) {
- $prepared_themes = array();
$current_theme = get_stylesheet();
+ // Make sure the current theme is listed first.
+ $prepared_themes = array( $current_theme => array() );
+
if ( null === $themes ) {
$themes = wp_get_themes( array( 'allowed' => true ) );
if ( ! isset( $themes[ $current_theme ] ) ) {
@@ -406,7 +408,7 @@ function wp_prepare_themes_for_js( $themes = null ) {
$slug = $theme->get_stylesheet();
$encoded_slug = urlencode( $slug );
- $prepared_themes[] = array(
+ $prepared_themes[ $slug ] = array(
'id' => $slug,
'name' => $theme->display( 'Name' ),
'screenshot' => array( $theme->get_screenshot() ), // @todo multiple
@@ -422,6 +424,13 @@ function wp_prepare_themes_for_js( $themes = null ) {
'actions' => array(
'activate' => current_user_can( 'switch_themes' ) ? wp_nonce_url( admin_url( 'themes.php?action=activate&stylesheet=' . $encoded_slug ), 'switch-theme_' . $slug ) : null,
'customize'=> current_user_can( 'edit_theme_options' ) ? wp_customize_url( $slug ) : null,
+ 'preview' => add_query_arg( array(
+ 'preview' => 1,
+ 'template' => urlencode( $theme->get_template() ),
+ 'stylesheet' => urlencode( $slug ),
+ 'preview_iframe' => true,
+ 'TB_iframe' => true,
+ ), home_url( '/' ) ),
'delete' => current_user_can( 'delete_themes' ) ? wp_nonce_url( admin_url( 'themes.php?action=delete&stylesheet=' . $encoded_slug ), 'delete-theme_' . $slug ) : null,
),
);
@@ -436,5 +445,6 @@ function wp_prepare_themes_for_js( $themes = null ) {
*
* @param array $prepared_themes Array of themes.
*/
- return apply_filters( 'wp_prepare_themes_for_js', $prepared_themes );
+ $prepared_themes = apply_filters( 'wp_prepare_themes_for_js', $prepared_themes );
+ return array_values( $prepared_themes );
}
\ No newline at end of file
diff --git a/src/wp-admin/js/theme.js b/src/wp-admin/js/theme.js
index 1739b086db..ef2dee786c 100644
--- a/src/wp-admin/js/theme.js
+++ b/src/wp-admin/js/theme.js
@@ -51,7 +51,7 @@ themes.view.Appearance = wp.Backbone.View.extend({
// Render and append
this.view.render();
- this.$el.append( this.view.el );
+ this.$el.empty().append( this.view.el ).addClass('rendered');
this.$el.append( '
' );
},
diff --git a/src/wp-admin/network/themes.php b/src/wp-admin/network/themes.php
index 135c1e4138..aada6edb70 100644
--- a/src/wp-admin/network/themes.php
+++ b/src/wp-admin/network/themes.php
@@ -218,7 +218,7 @@ get_current_screen()->set_help_sidebar(
$title = __('Themes');
$parent_file = 'themes.php';
-wp_enqueue_script( 'theme' );
+wp_enqueue_script( 'theme-preview' );
require_once(ABSPATH . 'wp-admin/admin-header.php');
diff --git a/src/wp-admin/theme-install.php b/src/wp-admin/theme-install.php
index 55d6de99c4..45fb870856 100644
--- a/src/wp-admin/theme-install.php
+++ b/src/wp-admin/theme-install.php
@@ -30,7 +30,7 @@ if ( !is_network_admin() )
$submenu_file = 'themes.php';
wp_enqueue_script( 'theme-install' );
-wp_enqueue_script( 'theme' );
+wp_enqueue_script( 'theme-preview' );
$body_id = $tab;
diff --git a/src/wp-admin/themes.php b/src/wp-admin/themes.php
index 2351b84dab..fa532548e6 100644
--- a/src/wp-admin/themes.php
+++ b/src/wp-admin/themes.php
@@ -116,7 +116,7 @@ require_once( ABSPATH . 'wp-admin/admin-header.php' );