Make WordPress Core

Ticket #29071: 29071.2.diff

File 29071.2.diff, 7.5 KB (added by ericlewis, 12 years ago)
  • src/wp-admin/customize.php

    diff --git a/src/wp-admin/customize.php b/src/wp-admin/customize.php
    index b5524b0..87a0ec5 100644
    a b do_action( 'customize_controls_print_scripts' );  
    189189         */
    190190        do_action( 'customize_controls_print_footer_scripts' );
    191191
    192         /*
    193          * If the frontend and the admin are served from the same domain, load the
    194          * preview over ssl if the customizer is being loaded over ssl. This avoids
    195          * insecure content warnings. This is not attempted if the admin and frontend
    196          * are on different domains to avoid the case where the frontend doesn't have
    197          * ssl certs. Domain mapping plugins can allow other urls in these conditions
    198          * using the customize_allowed_urls filter.
    199          */
    200 
    201         $allowed_urls = array( home_url('/') );
    202         $admin_origin = parse_url( admin_url() );
    203         $home_origin  = parse_url( home_url() );
    204         $cross_domain = ( strtolower( $admin_origin[ 'host' ] ) != strtolower( $home_origin[ 'host' ] ) );
    205 
    206         if ( is_ssl() && ! $cross_domain )
    207                 $allowed_urls[] = home_url( '/', 'https' );
    208 
    209         /**
    210          * Filter the list of URLs allowed to be clicked and followed in the Customizer preview.
    211          *
    212          * @since 3.4.0
    213          *
    214          * @param array $allowed_urls An array of allowed URLs.
    215          */
    216         $allowed_urls = array_unique( apply_filters( 'customize_allowed_urls', $allowed_urls ) );
    217 
    218         $fallback_url = add_query_arg( array(
    219                 'preview'        => 1,
    220                 'template'       => $wp_customize->get_template(),
    221                 'stylesheet'     => $wp_customize->get_stylesheet(),
    222                 'preview_iframe' => true,
    223                 'TB_iframe'      => 'true'
    224         ), home_url( '/' ) );
    225 
    226         $login_url = add_query_arg( array(
    227                 'interim-login' => 1,
    228                 'customize-login' => 1
    229         ), wp_login_url() );
    230 
    231         // Prepare customizer settings to pass to Javascript.
    232         $settings = array(
    233                 'theme'    => array(
    234                         'stylesheet' => $wp_customize->get_stylesheet(),
    235                         'active'     => $wp_customize->is_theme_active(),
    236                 ),
    237                 'url'      => array(
    238                         'preview'       => esc_url_raw( $url ? $url : home_url( '/' ) ),
    239                         'parent'        => esc_url_raw( admin_url() ),
    240                         'activated'     => esc_url_raw( admin_url( 'themes.php?activated=true&previewed' ) ),
    241                         'ajax'          => esc_url_raw( admin_url( 'admin-ajax.php', 'relative' ) ),
    242                         'allowed'       => array_map( 'esc_url_raw', $allowed_urls ),
    243                         'isCrossDomain' => $cross_domain,
    244                         'fallback'      => esc_url_raw( $fallback_url ),
    245                         'home'          => esc_url_raw( home_url( '/' ) ),
    246                         'login'         => esc_url_raw( $login_url ),
    247                 ),
    248                 'browser'  => array(
    249                         'mobile' => wp_is_mobile(),
    250                         'ios'    => $is_ios,
    251                 ),
    252                 'settings' => array(),
    253                 'controls' => array(),
    254                 'nonce'    => array(
    255                         'save'    => wp_create_nonce( 'save-customize_' . $wp_customize->get_stylesheet() ),
    256                         'preview' => wp_create_nonce( 'preview-customize_' . $wp_customize->get_stylesheet() )
    257                 ),
    258         );
    259 
    260         // Prepare Customize Setting objects to pass to Javascript.
    261         foreach ( $wp_customize->settings() as $id => $setting ) {
    262                 $settings['settings'][ $id ] = array(
    263                         'value'     => $setting->js_value(),
    264                         'transport' => $setting->transport,
    265                 );
    266         }
    267 
    268         // Prepare Customize Control objects to pass to Javascript.
    269         foreach ( $wp_customize->controls() as $id => $control ) {
    270                 $control->to_json();
    271                 $settings['controls'][ $id ] = $control->json;
    272         }
     192        $settings = $wp_customize->get_settings_for_js();
    273193
    274194        ?>
    275195        <script type="text/javascript">
  • src/wp-includes/class-wp-customize-manager.php

    diff --git a/src/wp-includes/class-wp-customize-manager.php b/src/wp-includes/class-wp-customize-manager.php
    index 5067126..69a2aca 100644
    a b final class WP_Customize_Manager {  
    11821182                if ( 'blank' === $color )
    11831183                        return 'blank';
    11841184
    1185                 $color = sanitize_hex_color_no_hash( $color );
    1186                 if ( empty( $color ) )
    1187                         $color = get_theme_support( 'custom-header', 'default-text-color' );
     1185                        $color = sanitize_hex_color_no_hash( $color );
     1186                        if ( empty( $color ) )
     1187                                $color = get_theme_support( 'custom-header', 'default-text-color' );
    11881188
    1189                 return $color;
     1189                        return $color;
     1190                }
     1191
     1192        /**
     1193         * Get settings array for Javascript.
     1194         *
     1195         * @since 4.0.0
     1196         *
     1197         * @return array
     1198         */
     1199        public function get_settings_for_js() {
     1200                global $is_ios, $url;
     1201                if ( empty( $is_ios ) ) {
     1202                        $is_ios = wp_is_mobile() && preg_match( '/iPad|iPod|iPhone/', $_SERVER['HTTP_USER_AGENT'] );
     1203                }
     1204                if ( empty( $url ) ) {
     1205                        wp_reset_vars( array( 'url', 'return' ) );
     1206                        $url = wp_unslash( $url );
     1207                        $url = wp_validate_redirect( $url, home_url( '/' ) );
     1208                }
     1209
     1210                /*
     1211                 * If the frontend and the admin are served from the same domain, load the
     1212                 * preview over ssl if the customizer is being loaded over ssl. This avoids
     1213                 * insecure content warnings. This is not attempted if the admin and frontend
     1214                 * are on different domains to avoid the case where the frontend doesn't have
     1215                 * ssl certs. Domain mapping plugins can allow other urls in these conditions
     1216                 * using the customize_allowed_urls filter.
     1217                 */
     1218
     1219                $allowed_urls = array( home_url('/') );
     1220                $admin_origin = parse_url( admin_url() );
     1221                $home_origin  = parse_url( home_url() );
     1222                $cross_domain = ( strtolower( $admin_origin[ 'host' ] ) != strtolower( $home_origin[ 'host' ] ) );
     1223
     1224                if ( is_ssl() && ! $cross_domain )
     1225                        $allowed_urls[] = home_url( '/', 'https' );
     1226
     1227                /**
     1228                 * Filter the list of URLs allowed to be clicked and followed in the Customizer preview.
     1229                 *
     1230                 * @since 3.4.0
     1231                 *
     1232                 * @param array $allowed_urls An array of allowed URLs.
     1233                 */
     1234                $allowed_urls = array_unique( apply_filters( 'customize_allowed_urls', $allowed_urls ) );
     1235
     1236                $fallback_url = add_query_arg( array(
     1237                        'preview'        => 1,
     1238                        'template'       => $this->get_template(),
     1239                        'stylesheet'     => $this->get_stylesheet(),
     1240                        'preview_iframe' => true,
     1241                        'TB_iframe'      => 'true'
     1242                ), home_url( '/' ) );
     1243
     1244                $login_url = add_query_arg( array(
     1245                        'interim-login' => 1,
     1246                        'customize-login' => 1
     1247                ), wp_login_url() );
     1248
     1249                // Prepare customizer settings to pass to Javascript.
     1250                $settings = array(
     1251                        'theme'    => array(
     1252                                'stylesheet' => $this->get_stylesheet(),
     1253                                'active'     => $this->is_theme_active(),
     1254                        ),
     1255                        'url'      => array(
     1256                                'preview'       => esc_url_raw( $url ? $url : home_url( '/' ) ),
     1257                                'parent'        => esc_url_raw( admin_url() ),
     1258                                'activated'     => esc_url_raw( admin_url( 'themes.php?activated=true&previewed' ) ),
     1259                                'ajax'          => esc_url_raw( admin_url( 'admin-ajax.php', 'relative' ) ),
     1260                                'allowed'       => array_map( 'esc_url_raw', $allowed_urls ),
     1261                                'isCrossDomain' => $cross_domain,
     1262                                'fallback'      => esc_url_raw( $fallback_url ),
     1263                                'home'          => esc_url_raw( home_url( '/' ) ),
     1264                                'login'         => esc_url_raw( $login_url ),
     1265                        ),
     1266                        'browser'  => array(
     1267                                'mobile' => wp_is_mobile(),
     1268                                'ios'    => $is_ios,
     1269                        ),
     1270                        'settings' => array(),
     1271                        'controls' => array(),
     1272                        'nonce'    => array(
     1273                                'save'    => wp_create_nonce( 'save-customize_' . $this->get_stylesheet() ),
     1274                                'preview' => wp_create_nonce( 'preview-customize_' . $this->get_stylesheet() )
     1275                        ),
     1276                );
     1277
     1278                // Prepare Customize Setting objects to pass to Javascript.
     1279                foreach ( $this->settings() as $id => $setting ) {
     1280                        $settings['settings'][ $id ] = array(
     1281                                'value'     => $setting->js_value(),
     1282                                'transport' => $setting->transport,
     1283                        );
     1284                }
     1285
     1286                // Prepare Customize Control objects to pass to Javascript.
     1287                foreach ( $this->controls() as $id => $control ) {
     1288                        $control->to_json();
     1289                        $settings['controls'][ $id ] = $control->json;
     1290                }
     1291                return $settings;
    11901292        }
    11911293}
    11921294