From c2fb0c425b00c70a5d31bacf4130cf73740dc73b Mon Sep 17 00:00:00 2001 From: koopersmith Date: Tue, 10 Apr 2012 02:25:03 +0000 Subject: [PATCH] Replace all instances of thickbox theme preview with the theme customizer. fixes #20404. * Use theme customizer in theme install/update screens. * Separate the customize loader from the customizer. Use wp_customize_loader() to include the loader script and markup. * Deprecated: wp-admin/js/theme-preview.js is now no longer used by core. git-svn-id: http://svn.automattic.com/wordpress/trunk@20419 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/class-wp-upgrader.php | 64 ++++++++++++++++++------- wp-admin/theme-install.php | 3 -- wp-admin/themes.php | 3 +- wp-admin/update.php | 13 ++--- wp-includes/class-wp-customize.php | 21 -------- wp-includes/general-template.php | 2 +- wp-includes/js/customize-loader.dev.js | 2 +- wp-includes/script-loader.php | 3 +- wp-includes/theme.php | 42 ++++++++++++++-- 9 files changed, 97 insertions(+), 56 deletions(-) diff --git a/wp-admin/includes/class-wp-upgrader.php b/wp-admin/includes/class-wp-upgrader.php index 408dbc0e0a..530c074ee5 100644 --- a/wp-admin/includes/class-wp-upgrader.php +++ b/wp-admin/includes/class-wp-upgrader.php @@ -711,7 +711,7 @@ class Theme_Upgrader extends WP_Upgrader { $this->strings['process_success_specific'] = $this->strings['parent_theme_install_success'];//, $api->name, $api->version); $this->skin->feedback('parent_theme_prepare_install', $api->name, $api->version); - + add_filter('install_theme_complete_actions', '__return_false', 999); // Don't show any actions after installing the theme. // Install the parent theme @@ -735,7 +735,7 @@ class Theme_Upgrader extends WP_Upgrader { return $install_result; } - + function hide_activate_preview_actions($actions) { unset($actions['activate'], $actions['preview']); return $actions; @@ -1494,19 +1494,33 @@ class Theme_Installer_Skin extends WP_Upgrader_Skin { return; $theme_info = $this->upgrader->theme_info(); - if ( empty($theme_info) ) + if ( empty( $theme_info ) ) return; - $name = $theme_info->display('Name'); + + $name = $theme_info->display('Name'); $stylesheet = $this->upgrader->result['destination_name']; - $template = $theme_info->get_template(); + $template = $theme_info->get_template(); - $preview_link = htmlspecialchars( add_query_arg( array('preview' => 1, 'template' => $template, 'stylesheet' => $stylesheet, 'preview_iframe' => 1, 'TB_iframe' => 'true' ), trailingslashit(esc_url(get_option('home'))) ) ); - $activate_link = wp_nonce_url("themes.php?action=activate&template=" . urlencode($template) . "&stylesheet=" . urlencode($stylesheet), 'switch-theme_' . $template); + $preview_link = add_query_arg( array( + 'preview' => 1, + 'template' => $template, + 'stylesheet' => $stylesheet, + ), trailingslashit( get_home_url() ) ); - $install_actions = array( - 'preview' => '' . __('Preview') . '', - 'activate' => '' . __('Activate') . '' - ); + $customize_attributes = 'title="' . esc_attr( sprintf( __( 'Customize “%s”' ), $name ) ) . '" + . data-customize-template="' . esc_attr( $template ) . '" data-customize-stylesheet="' . esc_attr( $stylesheet ) . '"'; + + $activate_link = add_query_arg( array( + 'action' => 'activate', + 'template' => $template, + 'stylesheet' => $stylesheet, + ), admin_url('themes.php') ); + $activate_link = wp_nonce_url( $activate_link, 'switch-theme_' . $template ); + + $install_actions = array(); + $install_actions['preview'] = '' . __('Preview') . ''; + $install_actions['preview'] .= '' . __('Customize') . ''; + $install_actions['activate'] = '' . __('Activate') . ''; if ( is_network_admin() && current_user_can( 'manage_network_themes' ) ) $install_actions['network_enable'] = '' . __( 'Network Enable' ) . ''; @@ -1550,17 +1564,31 @@ class Theme_Upgrader_Skin extends WP_Upgrader_Skin { $update_actions = array(); if ( ! empty( $this->upgrader->result['destination_name'] ) && $theme_info = $this->upgrader->theme_info() ) { - $name = $theme_info->display('Name'); + $name = $theme_info->display('Name'); $stylesheet = $this->upgrader->result['destination_name']; - $template = $theme_info->get_template(); + $template = $theme_info->get_template(); - $preview_link = htmlspecialchars( add_query_arg( array('preview' => 1, 'template' => $template, 'stylesheet' => $stylesheet, 'TB_iframe' => 'true' ), trailingslashit(esc_url(get_option('home'))) ) ); - $activate_link = wp_nonce_url("themes.php?action=activate&template=" . urlencode($template) . "&stylesheet=" . urlencode($stylesheet), 'switch-theme_' . $template); + $preview_link = add_query_arg( array( + 'preview' => 1, + 'template' => $template, + 'stylesheet' => $stylesheet, + ), trailingslashit( get_home_url() ) ); - $update_actions['preview'] = '' . __('Preview') . ''; - $update_actions['activate'] = '' . __('Activate') . ''; + $customize_attributes = 'title="' . esc_attr( sprintf( __( 'Customize “%s”' ), $name ) ) . '" + . data-customize-template="' . esc_attr( $template ) . '" data-customize-stylesheet="' . esc_attr( $stylesheet ) . '"'; - if ( ( ! $this->result || is_wp_error($this->result) ) || $stylesheet == get_stylesheet() ) + $activate_link = add_query_arg( array( + 'action' => 'activate', + 'template' => $template, + 'stylesheet' => $stylesheet, + ), admin_url('themes.php') ); + $activate_link = wp_nonce_url( $activate_link, 'switch-theme_' . $template ); + + $update_actions['preview'] = '' . __('Preview') . ''; + $update_actions['preview'] .= '' . __('Customize') . ''; + $update_actions['activate'] = '' . __('Activate') . ''; + + if ( ( ! $this->result || is_wp_error( $this->result ) ) || $stylesheet == get_stylesheet() ) unset($update_actions['preview'], $update_actions['activate']); } diff --git a/wp-admin/theme-install.php b/wp-admin/theme-install.php index 59dd842589..d405a588d2 100644 --- a/wp-admin/theme-install.php +++ b/wp-admin/theme-install.php @@ -30,9 +30,6 @@ if ( !is_network_admin() ) $submenu_file = 'themes.php'; wp_enqueue_script( 'theme-install' ); - -add_thickbox(); -wp_enqueue_script( 'theme-preview' ); wp_enqueue_script( 'theme' ); $body_id = $tab; diff --git a/wp-admin/themes.php b/wp-admin/themes.php index 19b35ba2b9..b9a37ec969 100644 --- a/wp-admin/themes.php +++ b/wp-admin/themes.php @@ -66,9 +66,8 @@ get_current_screen()->set_help_sidebar( '

' . __('Support Forums') . '

' ); -add_thickbox(); -wp_enqueue_script( 'theme-preview' ); wp_enqueue_script( 'theme' ); +wp_customize_loader(); endif; diff --git a/wp-admin/update.php b/wp-admin/update.php index 76be2169ed..2554ad0c69 100644 --- a/wp-admin/update.php +++ b/wp-admin/update.php @@ -152,8 +152,8 @@ if ( isset($_GET['action']) ) { check_admin_referer('upgrade-theme_' . $theme); - add_thickbox(); - wp_enqueue_script('theme-preview'); + wp_customize_loader(); + $title = __('Update Theme'); $parent_file = 'themes.php'; $submenu_file = 'themes.php'; @@ -204,8 +204,8 @@ if ( isset($_GET['action']) ) { if ( is_wp_error($api) ) wp_die($api); - add_thickbox(); - wp_enqueue_script('theme-preview'); + wp_customize_loader(); + $title = __('Install Themes'); $parent_file = 'themes.php'; $submenu_file = 'themes.php'; @@ -230,11 +230,12 @@ if ( isset($_GET['action']) ) { $file_upload = new File_Upload_Upgrader('themezip', 'package'); + wp_customize_loader(); + $title = __('Upload Theme'); $parent_file = 'themes.php'; $submenu_file = 'theme-install.php'; - add_thickbox(); - wp_enqueue_script('theme-preview'); + require_once(ABSPATH . 'wp-admin/admin-header.php'); $title = sprintf( __('Installing Theme from uploaded file: %s'), basename( $file_upload->filename ) ); diff --git a/wp-includes/class-wp-customize.php b/wp-includes/class-wp-customize.php index 8c9fde31b5..33e0fef11d 100644 --- a/wp-includes/class-wp-customize.php +++ b/wp-includes/class-wp-customize.php @@ -29,7 +29,6 @@ final class WP_Customize { add_action( 'setup_theme', array( $this, 'setup_theme' ) ); add_action( 'admin_init', array( $this, 'admin_init' ) ); add_action( 'wp_loaded', array( $this, 'wp_loaded' ) ); - add_action( 'admin_footer', array( $this, 'admin_footer' ) ); add_action( 'customize_previewing', array( $this, 'customize_previewing' ) ); add_action( 'customize_register', array( $this, 'register_controls' ) ); @@ -275,8 +274,6 @@ final class WP_Customize { if ( isset( $_REQUEST['save_customize_controls'] ) ) $this->save(); - wp_enqueue_script( 'customize-loader' ); - if ( ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) return; @@ -294,24 +291,6 @@ final class WP_Customize { die; } - /** - * Print the customize template. - * - * @since 3.4.0 - */ - public function admin_footer() { - ?> -
- - - - - - -
- add( 'admin-widgets', "/wp-admin/js/widgets$suffix.js", array( 'jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-droppable' ), false, 1 ); - $scripts->add( 'theme', "/wp-admin/js/theme$suffix.js", array( 'thickbox' ), false, 1 ); + $scripts->add( 'theme', "/wp-admin/js/theme$suffix.js", array( 'jquery' ), false, 1 ); + // @todo: Core no longer uses theme-preview.js. Remove? $scripts->add( 'theme-preview', "/wp-admin/js/theme-preview$suffix.js", array( 'thickbox', 'jquery' ), false, 1 ); $scripts->add( 'inline-edit-post', "/wp-admin/js/inline-edit-post$suffix.js", array( 'jquery', 'suggest' ), false, 1 ); diff --git a/wp-includes/theme.php b/wp-includes/theme.php index 200c957d03..72fa46f33b 100644 --- a/wp-includes/theme.php +++ b/wp-includes/theme.php @@ -1563,9 +1563,16 @@ function check_theme_switched() { } } -function wp_customize_load() { +/** + * Includes and instantiates the WP_Customize class. + * + * Fires when ?customize=on. + * + * @since 3.4.0 + */ +function _wp_customize_include() { // Load on themes.php or ?customize=on - if ( ! ( isset( $_REQUEST['customize'] ) && 'on' == $_REQUEST['customize'] ) && 'themes.php' != $GLOBALS['pagenow'] ) + if ( ! ( isset( $_REQUEST['customize'] ) && 'on' == $_REQUEST['customize'] ) ) return; require( ABSPATH . WPINC . '/class-wp-customize.php' ); @@ -1573,4 +1580,33 @@ function wp_customize_load() { // @todo Dependency injection instead $GLOBALS['customize'] = new WP_Customize; } -add_action( 'plugins_loaded', 'wp_customize_load' ); +add_action( 'plugins_loaded', '_wp_customize_include' ); + +/** + * Includes the loading scripts for the theme customizer and + * adds the action to print the customize container template. + * + * @since 3.4.0 + */ +function wp_customize_loader() { + wp_enqueue_script( 'customize-loader' ); + add_action( 'admin_footer', '_wp_customize_loader_template' ); +} + +/** + * Print the customize container template. + * + * @since 3.4.0 + */ +function _wp_customize_loader_template() { + ?> +
+ + + + + + +
+