Make WordPress Core

Changeset 20419


Ignore:
Timestamp:
04/10/2012 02:25:03 AM (13 years ago)
Author:
koopersmith
Message:

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.
Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/class-wp-upgrader.php

    r20329 r20419  
    712712
    713713        $this->skin->feedback('parent_theme_prepare_install', $api->name, $api->version);
    714        
     714
    715715        add_filter('install_theme_complete_actions', '__return_false', 999); // Don't show any actions after installing the theme.
    716716
     
    736736        return $install_result;
    737737    }
    738    
     738
    739739    function hide_activate_preview_actions($actions) {
    740740        unset($actions['activate'], $actions['preview']);
     
    14951495
    14961496        $theme_info = $this->upgrader->theme_info();
    1497         if ( empty($theme_info) )
     1497        if ( empty( $theme_info ) )
    14981498            return;
    1499         $name = $theme_info->display('Name');
     1499
     1500        $name       = $theme_info->display('Name');
    15001501        $stylesheet = $this->upgrader->result['destination_name'];
    1501         $template = $theme_info->get_template();
    1502 
    1503         $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'))) ) );
    1504         $activate_link = wp_nonce_url("themes.php?action=activate&template=" . urlencode($template) . "&stylesheet=" . urlencode($stylesheet), 'switch-theme_' . $template);
    1505 
    1506         $install_actions = array(
    1507             'preview' => '<a href="' . $preview_link . '" class="thickbox thickbox-preview" title="' . esc_attr(sprintf(__('Preview &#8220;%s&#8221;'), $name)) . '">' . __('Preview') . '</a>',
    1508             'activate' => '<a href="' . $activate_link . '" class="activatelink" title="' . esc_attr( sprintf( __('Activate &#8220;%s&#8221;'), $name ) ) . '">' . __('Activate') . '</a>'
    1509                             );
     1502        $template   = $theme_info->get_template();
     1503
     1504        $preview_link = add_query_arg( array(
     1505            'preview'    => 1,
     1506            'template'   => $template,
     1507            'stylesheet' => $stylesheet,
     1508        ), trailingslashit( get_home_url() ) );
     1509
     1510        $customize_attributes = 'title="' . esc_attr( sprintf( __( 'Customize &#8220;%s&#8221;' ), $name ) ) . '"
     1511            . data-customize-template="' . esc_attr( $template ) . '" data-customize-stylesheet="' . esc_attr( $stylesheet ) . '"';
     1512
     1513        $activate_link = add_query_arg( array(
     1514            'action'     => 'activate',
     1515            'template'   => $template,
     1516            'stylesheet' => $stylesheet,
     1517        ), admin_url('themes.php') );
     1518        $activate_link = wp_nonce_url( $activate_link, 'switch-theme_' . $template );
     1519
     1520        $install_actions = array();
     1521        $install_actions['preview']  = '<a href="' . esc_url( $preview_link ) . '" class="hide-if-js" title="' . esc_attr(sprintf(__('Preview &#8220;%s&#8221;'), $name ) ) . '">' . __('Preview') . '</a>';
     1522        $install_actions['preview'] .= '<a href="#" class="hide-if-no-js load-customize" ' . $customize_attributes . '>' . __('Customize') . '</a>';
     1523        $install_actions['activate'] = '<a href="' . esc_url( $activate_link ) . '" class="activatelink" title="' . esc_attr( sprintf( __('Activate &#8220;%s&#8221;'), $name ) ) . '">' . __('Activate') . '</a>';
    15101524
    15111525        if ( is_network_admin() && current_user_can( 'manage_network_themes' ) )
     
    15511565        $update_actions = array();
    15521566        if ( ! empty( $this->upgrader->result['destination_name'] ) && $theme_info = $this->upgrader->theme_info() ) {
    1553             $name = $theme_info->display('Name');
     1567            $name       = $theme_info->display('Name');
    15541568            $stylesheet = $this->upgrader->result['destination_name'];
    1555             $template = $theme_info->get_template();
    1556 
    1557             $preview_link = htmlspecialchars( add_query_arg( array('preview' => 1, 'template' => $template, 'stylesheet' => $stylesheet, 'TB_iframe' => 'true' ), trailingslashit(esc_url(get_option('home'))) ) );
    1558             $activate_link = wp_nonce_url("themes.php?action=activate&amp;template=" . urlencode($template) . "&amp;stylesheet=" . urlencode($stylesheet), 'switch-theme_' . $template);
    1559 
    1560             $update_actions['preview'] = '<a href="' . $preview_link . '" class="thickbox thickbox-preview" title="' . esc_attr(sprintf(__('Preview &#8220;%s&#8221;'), $name)) . '">' . __('Preview') . '</a>';
    1561             $update_actions['activate'] = '<a href="' . $activate_link . '" class="activatelink" title="' . esc_attr( sprintf( __('Activate &#8220;%s&#8221;'), $name ) ) . '">' . __('Activate') . '</a>';
    1562 
    1563             if ( ( ! $this->result || is_wp_error($this->result) ) || $stylesheet == get_stylesheet() )
     1569            $template   = $theme_info->get_template();
     1570
     1571            $preview_link = add_query_arg( array(
     1572                'preview'    => 1,
     1573                'template'   => $template,
     1574                'stylesheet' => $stylesheet,
     1575            ), trailingslashit( get_home_url() ) );
     1576
     1577            $customize_attributes = 'title="' . esc_attr( sprintf( __( 'Customize &#8220;%s&#8221;' ), $name ) ) . '"
     1578                . data-customize-template="' . esc_attr( $template ) . '" data-customize-stylesheet="' . esc_attr( $stylesheet ) . '"';
     1579
     1580            $activate_link = add_query_arg( array(
     1581                'action'     => 'activate',
     1582                'template'   => $template,
     1583                'stylesheet' => $stylesheet,
     1584            ), admin_url('themes.php') );
     1585            $activate_link = wp_nonce_url( $activate_link, 'switch-theme_' . $template );
     1586
     1587            $update_actions['preview']  = '<a href="' . esc_url( $preview_link ) . '" class="hide-if-js" title="' . esc_attr(sprintf(__('Preview &#8220;%s&#8221;'), $name ) ) . '">' . __('Preview') . '</a>';
     1588            $update_actions['preview'] .= '<a href="#" class="hide-if-no-js load-customize" ' . $customize_attributes . '>' . __('Customize') . '</a>';
     1589            $update_actions['activate'] = '<a href="' . esc_url( $activate_link ) . '" class="activatelink" title="' . esc_attr( sprintf( __('Activate &#8220;%s&#8221;'), $name ) ) . '">' . __('Activate') . '</a>';
     1590
     1591            if ( ( ! $this->result || is_wp_error( $this->result ) ) || $stylesheet == get_stylesheet() )
    15641592                unset($update_actions['preview'], $update_actions['activate']);
    15651593        }
  • trunk/wp-admin/theme-install.php

    r19887 r20419  
    3131
    3232wp_enqueue_script( 'theme-install' );
    33 
    34 add_thickbox();
    35 wp_enqueue_script( 'theme-preview' );
    3633wp_enqueue_script( 'theme' );
    3734
  • trunk/wp-admin/themes.php

    r20354 r20419  
    6767);
    6868
    69 add_thickbox();
    70 wp_enqueue_script( 'theme-preview' );
    7169wp_enqueue_script( 'theme' );
     70wp_customize_loader();
    7271
    7372endif;
  • trunk/wp-admin/update.php

    r20267 r20419  
    153153        check_admin_referer('upgrade-theme_' . $theme);
    154154
    155         add_thickbox();
    156         wp_enqueue_script('theme-preview');
     155        wp_customize_loader();
     156
    157157        $title = __('Update Theme');
    158158        $parent_file = 'themes.php';
     
    205205            wp_die($api);
    206206
    207         add_thickbox();
    208         wp_enqueue_script('theme-preview');
     207        wp_customize_loader();
     208
    209209        $title = __('Install Themes');
    210210        $parent_file = 'themes.php';
     
    231231        $file_upload = new File_Upload_Upgrader('themezip', 'package');
    232232
     233        wp_customize_loader();
     234
    233235        $title = __('Upload Theme');
    234236        $parent_file = 'themes.php';
    235237        $submenu_file = 'theme-install.php';
    236         add_thickbox();
    237         wp_enqueue_script('theme-preview');
     238
    238239        require_once(ABSPATH . 'wp-admin/admin-header.php');
    239240
  • trunk/wp-includes/class-wp-customize.php

    r20392 r20419  
    3030        add_action( 'admin_init',   array( $this, 'admin_init' ) );
    3131        add_action( 'wp_loaded',    array( $this, 'wp_loaded' ) );
    32         add_action( 'admin_footer', array( $this, 'admin_footer' ) );
    3332
    3433        add_action( 'customize_previewing',               array( $this, 'customize_previewing' ) );
     
    276275            $this->save();
    277276
    278         wp_enqueue_script( 'customize-loader' );
    279 
    280277        if ( ( defined( 'DOING_AJAX' ) && DOING_AJAX ) )
    281278            return;
     
    293290
    294291        die;
    295     }
    296 
    297     /**
    298      * Print the customize template.
    299      *
    300      * @since 3.4.0
    301      */
    302     public function admin_footer() {
    303         ?>
    304         <div id="customize-container" class="wp-full-overlay">
    305             <input type="hidden" class="admin-url" value="<?php echo esc_url( admin_url( 'admin.php' ) ); ?>" />
    306             <a href="#" class="close-full-overlay"><?php printf( __( '&larr; Return to %s' ), get_admin_page_title() ); ?></a>
    307             <a href="#" class="collapse-sidebar button-secondary" title="<?php esc_attr_e('Collapse Sidebar'); ?>">
    308                 <span class="collapse-sidebar-label"><?php _e('Collapse'); ?></span>
    309                 <span class="collapse-sidebar-arrow"></span>
    310             </a>
    311         </div>
    312         <?php
    313292    }
    314293
  • trunk/wp-includes/general-template.php

    r20417 r20419  
    21092109 *
    21102110 * If any of the settings need to be changed, this can be done with another js
    2111  * file similar to media-upload.js and theme-preview.js. That file should
     2111 * file similar to media-upload.js. That file should
    21122112 * require array('thickbox') to ensure it is loaded after.
    21132113 *
  • trunk/wp-includes/js/customize-loader.dev.js

    r20352 r20419  
    4242        Loader.initialize();
    4343
    44         $('#current-theme, #availablethemes').on( 'click', '.load-customize', function( event ) {
     44        $('#wpbody').on( 'click', '.load-customize', function( event ) {
    4545            var load = $(this);
    4646
  • trunk/wp-includes/script-loader.php

    r20358 r20419  
    365365        $scripts->add( 'admin-widgets', "/wp-admin/js/widgets$suffix.js", array( 'jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-droppable' ), false, 1 );
    366366
    367         $scripts->add( 'theme', "/wp-admin/js/theme$suffix.js", array( 'thickbox' ), false, 1 );
    368 
     367        $scripts->add( 'theme', "/wp-admin/js/theme$suffix.js", array( 'jquery' ), false, 1 );
     368
     369        // @todo: Core no longer uses theme-preview.js. Remove?
    369370        $scripts->add( 'theme-preview', "/wp-admin/js/theme-preview$suffix.js", array( 'thickbox', 'jquery' ), false, 1 );
    370371
  • trunk/wp-includes/theme.php

    r20375 r20419  
    15641564}
    15651565
    1566 function wp_customize_load() {
     1566/**
     1567 * Includes and instantiates the WP_Customize class.
     1568 *
     1569 * Fires when ?customize=on.
     1570 *
     1571 * @since 3.4.0
     1572 */
     1573function _wp_customize_include() {
    15671574    // Load on themes.php or ?customize=on
    1568     if ( ! ( isset( $_REQUEST['customize'] ) && 'on' == $_REQUEST['customize'] ) && 'themes.php' != $GLOBALS['pagenow'] )
     1575    if ( ! ( isset( $_REQUEST['customize'] ) && 'on' == $_REQUEST['customize'] ) )
    15691576        return;
    15701577
     
    15741581    $GLOBALS['customize'] = new WP_Customize;
    15751582}
    1576 add_action( 'plugins_loaded', 'wp_customize_load' );
     1583add_action( 'plugins_loaded', '_wp_customize_include' );
     1584
     1585/**
     1586 * Includes the loading scripts for the theme customizer and
     1587 * adds the action to print the customize container template.
     1588 *
     1589 * @since 3.4.0
     1590 */
     1591function wp_customize_loader() {
     1592    wp_enqueue_script( 'customize-loader' );
     1593    add_action( 'admin_footer', '_wp_customize_loader_template' );
     1594}
     1595
     1596/**
     1597 * Print the customize container template.
     1598 *
     1599 * @since 3.4.0
     1600 */
     1601function _wp_customize_loader_template() {
     1602    ?>
     1603    <div id="customize-container" class="wp-full-overlay">
     1604        <input type="hidden" class="admin-url" value="<?php echo esc_url( admin_url( 'admin.php' ) ); ?>" />
     1605        <a href="#" class="close-full-overlay"><?php printf( __( '&larr; Return to %s' ), get_admin_page_title() ); ?></a>
     1606        <a href="#" class="collapse-sidebar button-secondary" title="<?php esc_attr_e('Collapse Sidebar'); ?>">
     1607            <span class="collapse-sidebar-label"><?php _e('Collapse'); ?></span>
     1608            <span class="collapse-sidebar-arrow"></span>
     1609        </a>
     1610    </div>
     1611    <?php
     1612}
Note: See TracChangeset for help on using the changeset viewer.