Make WordPress Core

Ticket #33898: 33898.diff

File 33898.diff, 3.2 KB (added by westonruter, 10 years ago)

https://github.com/xwp/wordpress-develop/pull/121

  • src/wp-admin/customize.php

    diff --git src/wp-admin/customize.php src/wp-admin/customize.php
    index 425af6f..20c95aa 100644
    do_action( 'customize_controls_print_scripts' ); 
    235235                        'mobile' => wp_is_mobile(),
    236236                        'ios'    => $is_ios,
    237237                ),
    238                 'settings' => array(),
    239                 'controls' => array(),
    240238                'panels'   => array(),
    241239                'sections' => array(),
    242240                'nonce'    => array(
    do_action( 'customize_controls_print_scripts' ); 
    247245                'documentTitleTmpl' => $document_title_tmpl,
    248246        );
    249247
    250         // Prepare Customize Setting objects to pass to JavaScript.
    251         foreach ( $wp_customize->settings() as $id => $setting ) {
    252                 if ( $setting->check_capabilities() ) {
    253                         $settings['settings'][ $id ] = array(
    254                                 'value'     => $setting->js_value(),
    255                                 'transport' => $setting->transport,
    256                                 'dirty'     => $setting->dirty,
    257                         );
    258                 }
    259         }
    260 
    261         // Prepare Customize Control objects to pass to JavaScript.
    262         foreach ( $wp_customize->controls() as $id => $control ) {
    263                 if ( $control->check_capabilities() ) {
    264                         $settings['controls'][ $id ] = $control->json();
    265                 }
    266         }
    267 
    268248        // Prepare Customize Section objects to pass to JavaScript.
    269249        foreach ( $wp_customize->sections() as $id => $section ) {
    270250                if ( $section->check_capabilities() ) {
    do_action( 'customize_controls_print_scripts' ); 
    289269                $autofocus = wp_unslash( $_GET['autofocus'] );
    290270                if ( is_array( $autofocus ) ) {
    291271                        foreach ( $autofocus as $type => $id ) {
    292                                 if ( isset( $settings[ $type . 's' ][ $id ] ) ) {
     272                                $can_autofocus = (
     273                                        ( 'control' === $type && $wp_customize->get_control( $id ) && $wp_customize->get_control( $id )->check_capabilities() )
     274                                        ||
     275                                        ( 'section' === $type && $wp_customize->get_section( $id ) && $wp_customize->get_section( $id )->check_capabilities() )
     276                                        ||
     277                                        ( 'panel' === $type && $wp_customize->get_panel( $id ) && $wp_customize->get_panel( $id )->check_capabilities() )
     278                                );
     279                                if ( $can_autofocus ) {
    293280                                        $settings['autofocus'][ $type ] = $id;
    294281                                }
    295282                        }
    do_action( 'customize_controls_print_scripts' ); 
    299286        ?>
    300287        <script type="text/javascript">
    301288                var _wpCustomizeSettings = <?php echo wp_json_encode( $settings ); ?>;
     289                _wpCustomizeSettings.controls = {};
     290                _wpCustomizeSettings.settings = {};
     291                <?php
     292
     293                // Serialize settings one by one to improve memory usage.
     294                echo "(function ( s ){\n";
     295                foreach ( $wp_customize->settings() as $setting ) {
     296                        if ( $setting->check_capabilities() ) {
     297                                printf(
     298                                        "s[%s] = %s;\n",
     299                                        wp_json_encode( $setting->id ),
     300                                        wp_json_encode( array(
     301                                                'value'     => $setting->js_value(),
     302                                                'transport' => $setting->transport,
     303                                                'dirty'     => $setting->dirty,
     304                                        ) )
     305                                );
     306                        }
     307                }
     308                echo "})( _wpCustomizeSettings.settings );\n";
     309
     310                // Serialize controls one by one to improve memory usage.
     311                echo "(function ( c ){\n";
     312                foreach ( $wp_customize->controls() as $control ) {
     313                        if ( $control->check_capabilities() ) {
     314                                printf(
     315                                        "c[%s] = %s;\n",
     316                                        wp_json_encode( $control->id ),
     317                                        wp_json_encode( $control->json() )
     318                                );
     319                        }
     320                }
     321                echo "})( _wpCustomizeSettings.controls );\n";
     322                ?>
    302323        </script>
    303324</div>
    304325</body>