Make WordPress Core


Ignore:
Timestamp:
12/06/2013 04:10:25 PM (10 years ago)
Author:
nacin
Message:

No-JavaScript and no-Customizer support for the new Themes screen.

JavaScript is rarely disabled, but graceful degradation is still important. For example, syntax errors can occur, usually with major WP updates that overhaul entire experiences and update external libraries combined with themes or plugins doing weird or old things. If this error is due to their current theme, a user needs to be able to access the themes screen to switch away from the theme. A more subtle issue could make things painful to diagnose.

This commit renders the grid in PHP (the template is duplicated, but it lightweight, fairly mundane, and easy to sync). On Backbone render, the grid is then re-rendered from JavaScript so searches can occur. Customize and Live Preview is disabled if JS fails to kick in. If JS is disabled, old-school "Preview" links are displayed.

No-Customizer support: The customizer is only supported when the browser supports postMessage (IE8+), and if the frontend is a different domain, CORS (IE10+). We use the .hide-if-no-customize class for this. Pre-customize "Preview" links should use .hide-if-customize.

The .load-customize class should be used to declare a link that opens the customizer. This enables customize-loader.js to intercept this link and load the customizer on top of the current window, making for a smoother experience.

fixes #25964.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/theme.php

    r26711 r26726  
    379379 */
    380380function wp_prepare_themes_for_js( $themes = null ) {
    381     $prepared_themes = array();
    382381    $current_theme = get_stylesheet();
     382
     383    // Make sure the current theme is listed first.
     384    $prepared_themes = array( $current_theme => array() );
    383385
    384386    if ( null === $themes ) {
     
    407409        $encoded_slug = urlencode( $slug );
    408410
    409         $prepared_themes[] = array(
     411        $prepared_themes[ $slug ] = array(
    410412            'id'           => $slug,
    411413            'name'         => $theme->display( 'Name' ),
     
    423425                'activate' => current_user_can( 'switch_themes' ) ? wp_nonce_url( admin_url( 'themes.php?action=activate&stylesheet=' . $encoded_slug ), 'switch-theme_' . $slug ) : null,
    424426                'customize'=> current_user_can( 'edit_theme_options' ) ? wp_customize_url( $slug ) : null,
     427                'preview'   => add_query_arg( array(
     428                    'preview'        => 1,
     429                    'template'       => urlencode( $theme->get_template() ),
     430                    'stylesheet'     => urlencode( $slug ),
     431                    'preview_iframe' => true,
     432                    'TB_iframe'      => true,
     433                ), home_url( '/' ) ),
    425434                'delete'   => current_user_can( 'delete_themes' ) ? wp_nonce_url( admin_url( 'themes.php?action=delete&stylesheet=' . $encoded_slug ), 'delete-theme_' . $slug ) : null,
    426435            ),
     
    437446     * @param array $prepared_themes Array of themes.
    438447     */
    439     return apply_filters( 'wp_prepare_themes_for_js', $prepared_themes );
    440 }
     448    $prepared_themes = apply_filters( 'wp_prepare_themes_for_js', $prepared_themes );
     449    return array_values( $prepared_themes );
     450}
Note: See TracChangeset for help on using the changeset viewer.