Make WordPress Core


Ignore:
Timestamp:
01/27/2016 05:54:39 PM (11 years ago)
Author:
westonruter
Message:

Customizer: Export nonce, theme, and url app settings in preview as exported in pane.

  • Introduce WP_Customize_Manager::get_nonces() to consolidate logic for retrieving nonces.
  • Export nonces centrally in wp.customize.settings.nonce with each request and update nav menus preview to utilize.
  • Send updated nonces to preview upon nonce-refresh.
  • Request full preview refresh if Nav Menu selective refresh request fails (e.g. due to bad nonce).
  • Update nav menus and widgets in Customizer to utilize customize_refresh_nonces for exporting nonces and keeping them up to date.

See #27355.
Fixes #35617.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-customize-nav-menus.php

    r36383 r36414  
    4949                $this->manager         = $manager;
    5050
     51                add_filter( 'customize_refresh_nonces', array( $this, 'filter_nonces' ) );
    5152                add_action( 'wp_ajax_load-available-menu-items-customizer', array( $this, 'ajax_load_available_items' ) );
    5253                add_action( 'wp_ajax_search-available-menu-items-customizer', array( $this, 'ajax_search_available_items' ) );
     
    6162                add_action( 'customize_controls_print_footer_scripts', array( $this, 'available_items_template' ) );
    6263                add_action( 'customize_preview_init', array( $this, 'customize_preview_init' ) );
     64        }
     65
     66        /**
     67         * Add nonce for customizing menus.
     68         *
     69         * @since 4.5.0
     70         * @access public
     71         *
     72         * @param  array $nonces Array of nonces.
     73         * @return array $nonces Array of nonces.
     74         */
     75        public function filter_nonces( $nonces ) {
     76                $nonces['customize-menus'] = wp_create_nonce( 'customize-menus' );
     77                return $nonces;
    6378        }
    6479
     
    330345                // Pass data to JS.
    331346                $settings = array(
    332                         'nonce'                => wp_create_nonce( 'customize-menus' ),
    333347                        'allMenus'             => wp_get_nav_menus(),
    334348                        'itemTypes'            => $this->available_item_types(),
     
    940954                        'renderNonceValue'      => wp_create_nonce( self::RENDER_AJAX_ACTION ),
    941955                        'renderNoncePostKey'    => self::RENDER_NONCE_POST_KEY,
    942                         'requestUri'            => empty( $_SERVER['REQUEST_URI'] ) ? home_url( '/' ) : esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ),
    943                         'theme'                 => array(
    944                                 'stylesheet' => $this->manager->get_stylesheet(),
    945                                 'active'     => $this->manager->is_theme_active(),
    946                         ),
    947                         'previewCustomizeNonce' => wp_create_nonce( 'preview-customize_' . $this->manager->get_stylesheet() ),
    948956                        'navMenuInstanceArgs'   => $this->preview_nav_menu_instance_args,
    949957                        'l10n'                  => array(
Note: See TracChangeset for help on using the changeset viewer.