WordPress.org

Make WordPress Core


Ignore:
Timestamp:
05/24/2012 09:13:21 PM (8 years ago)
Author:
koopersmith
Message:

Theme Customizer: Check for CORS support when the preview and admin urls are cross-domain. Add a fallback to the customize control frame, and check support there as well. see #20582, #19910.

File:
1 edited

Legend:

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

    r20864 r20886  
    15851585
    15861586/**
    1587  * Localizes the customize-loader script.
     1587 * Adds settings for the customize-loader script.
    15881588 *
    15891589 * @since 3.4.0
    15901590 */
    1591 function _wp_customize_loader_localize() {
    1592     wp_localize_script( 'customize-loader', 'wpCustomizeLoaderL10n', array(
    1593         'url' => admin_url( 'admin.php' ),
    1594     ) );
    1595 }
    1596 add_action( 'admin_enqueue_scripts', '_wp_customize_loader_localize' );
     1591function _wp_customize_loader_settings() {
     1592    global $wp_scripts;
     1593
     1594    $admin_origin = parse_url( admin_url() );
     1595    $home_origin  = parse_url( home_url() );
     1596    $cross_domain = ( strtolower( $admin_origin[ 'host' ] ) != strtolower( $home_origin[ 'host' ] ) );
     1597
     1598    $settings = array(
     1599        'url'           => esc_url( admin_url( 'admin.php' ) ),
     1600        'isCrossDomain' => $cross_domain,
     1601    );
     1602
     1603    $script = 'var _wpCustomizeLoaderSettings = ' . json_encode( $settings ) . ';';
     1604
     1605    $data = $wp_scripts->get_data( 'customize-loader', 'data' );
     1606    if ( $data )
     1607        $script = "$data\n$script";
     1608
     1609    $wp_scripts->add_data( 'customize-loader', 'data', $script );
     1610}
     1611add_action( 'admin_enqueue_scripts', '_wp_customize_loader_settings' );
    15971612
    15981613/**
Note: See TracChangeset for help on using the changeset viewer.