Changeset 36414
- Timestamp:
- 01/27/2016 05:54:39 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/js/customize-controls.js
r36407 r36414 3376 3376 $.extend( api.settings.nonce, nonce ); 3377 3377 $.extend( api.previewer.nonce, nonce ); 3378 api.previewer.send( 'nonce-refresh', nonce ); 3378 3379 }); 3379 3380 -
trunk/src/wp-admin/js/customize-nav-menus.js
r36383 r36414 324 324 self.loading = true; 325 325 params = { 326 'customize-menus-nonce': api. Menus.data.nonce,326 'customize-menus-nonce': api.settings.nonce['customize-menus'], 327 327 'wp_customize': 'on', 328 328 'type': type, -
trunk/src/wp-admin/js/customize-widgets.js
r35793 r36414 1108 1108 params.action = 'update-widget'; 1109 1109 params.wp_customize = 'on'; 1110 params.nonce = api. Widgets.data.nonce;1110 params.nonce = api.settings.nonce['update-widget']; 1111 1111 params.theme = api.settings.theme.stylesheet; 1112 1112 params.customized = wp.customize.previewer.query().customized; … … 2059 2059 }); 2060 2060 2061 // Refresh the nonce if login sends updated nonces over.2062 api.bind( 'nonce-refresh', function( nonces ) {2063 api.Widgets.data.nonce = nonces['update-widget'];2064 });2065 2066 2061 /** 2067 2062 * Init Customizer for widgets. -
trunk/src/wp-includes/class-wp-customize-manager.php
r36407 r36414 802 802 public function customize_preview_settings() { 803 803 $settings = array( 804 'theme' => array( 805 'stylesheet' => $this->get_stylesheet(), 806 'active' => $this->is_theme_active(), 807 ), 808 'url' => array( 809 'self' => empty( $_SERVER['REQUEST_URI'] ) ? home_url( '/' ) : esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ), 810 ), 804 811 'channel' => wp_unslash( $_POST['customize_messenger_channel'] ), 805 812 'activePanels' => array(), 806 813 'activeSections' => array(), 807 814 'activeControls' => array(), 815 'nonce' => $this->get_nonces(), 808 816 '_dirty' => array_keys( $this->unsanitized_post_values() ), 809 817 ); 810 811 if ( 2 == $this->nonce_tick ) {812 $settings['nonce'] = array(813 'save' => wp_create_nonce( 'save-customize_' . $this->get_stylesheet() ),814 'preview' => wp_create_nonce( 'preview-customize_' . $this->get_stylesheet() )815 );816 }817 818 818 819 foreach ( $this->panels as $panel_id => $panel ) { … … 1026 1027 } 1027 1028 1028 $nonces = array( 1029 'save' => wp_create_nonce( 'save-customize_' . $this->get_stylesheet() ), 1030 'preview' => wp_create_nonce( 'preview-customize_' . $this->get_stylesheet() ), 1031 ); 1032 1033 /** 1034 * Filter nonces for a customize_refresh_nonces AJAX request. 1035 * 1036 * @since 4.2.0 1037 * 1038 * @param array $nonces Array of refreshed nonces for save and 1039 * preview actions. 1040 * @param WP_Customize_Manager $this WP_Customize_Manager instance. 1041 */ 1042 $nonces = apply_filters( 'customize_refresh_nonces', $nonces, $this ); 1043 wp_send_json_success( $nonces ); 1029 wp_send_json_success( $this->get_nonces() ); 1044 1030 } 1045 1031 … … 1634 1620 public function get_autofocus() { 1635 1621 return $this->autofocus; 1622 } 1623 1624 /** 1625 * Get nonces for the Customizer. 1626 * 1627 * @since 4.5.0 1628 * @return array Nonces. 1629 */ 1630 public function get_nonces() { 1631 $nonces = array( 1632 'save' => wp_create_nonce( 'save-customize_' . $this->get_stylesheet() ), 1633 'preview' => wp_create_nonce( 'preview-customize_' . $this->get_stylesheet() ), 1634 ); 1635 1636 /** 1637 * Filter nonces for Customizer. 1638 * 1639 * @since 4.2.0 1640 * 1641 * @param array $nonces Array of refreshed nonces for save and 1642 * preview actions. 1643 * @param WP_Customize_Manager $this WP_Customize_Manager instance. 1644 */ 1645 $nonces = apply_filters( 'customize_refresh_nonces', $nonces, $this ); 1646 1647 return $nonces; 1636 1648 } 1637 1649 … … 1696 1708 'panels' => array(), 1697 1709 'sections' => array(), 1698 'nonce' => array( 1699 'save' => wp_create_nonce( 'save-customize_' . $this->get_stylesheet() ), 1700 'preview' => wp_create_nonce( 'preview-customize_' . $this->get_stylesheet() ), 1701 ), 1710 'nonce' => $this->get_nonces(), 1702 1711 'autofocus' => array(), 1703 1712 'documentTitleTmpl' => $this->get_document_title_template(), -
trunk/src/wp-includes/class-wp-customize-nav-menus.php
r36383 r36414 49 49 $this->manager = $manager; 50 50 51 add_filter( 'customize_refresh_nonces', array( $this, 'filter_nonces' ) ); 51 52 add_action( 'wp_ajax_load-available-menu-items-customizer', array( $this, 'ajax_load_available_items' ) ); 52 53 add_action( 'wp_ajax_search-available-menu-items-customizer', array( $this, 'ajax_search_available_items' ) ); … … 61 62 add_action( 'customize_controls_print_footer_scripts', array( $this, 'available_items_template' ) ); 62 63 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; 63 78 } 64 79 … … 330 345 // Pass data to JS. 331 346 $settings = array( 332 'nonce' => wp_create_nonce( 'customize-menus' ),333 347 'allMenus' => wp_get_nav_menus(), 334 348 'itemTypes' => $this->available_item_types(), … … 940 954 'renderNonceValue' => wp_create_nonce( self::RENDER_AJAX_ACTION ), 941 955 '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() ),948 956 'navMenuInstanceArgs' => $this->preview_nav_menu_instance_args, 949 957 'l10n' => array( -
trunk/src/wp-includes/class-wp-customize-widgets.php
r35793 r36414 662 662 663 663 $settings = array( 664 'nonce' => wp_create_nonce( 'update-widget' ),665 664 'registeredSidebars' => array_values( $wp_registered_sidebars ), 666 665 'registeredWidgets' => $wp_registered_widgets, -
trunk/src/wp-includes/js/customize-preview-nav-menus.js
r36383 r36414 14 14 renderNonceValue: null, 15 15 renderNoncePostKey: null, 16 previewCustomizeNonce: null,17 16 requestUri: '/', 18 theme: {19 active: false,20 stylesheet: ''21 },22 17 navMenuInstanceArgs: {}, 23 18 l10n: {} … … 201 196 202 197 data = { 203 nonce: settings.previewCustomizeNonce, // for Customize Preview198 nonce: wp.customize.settings.nonce.preview, 204 199 wp_customize: 'on' 205 200 }; 206 if ( ! settings.theme.active ) {207 data.theme = settings.theme.stylesheet;201 if ( ! wp.customize.settings.theme.active ) { 202 data.theme = wp.customize.settings.theme.stylesheet; 208 203 } 209 204 data[ settings.renderQueryVar ] = '1'; … … 240 235 request = wp.ajax.send( null, { 241 236 data: data, 242 url: settings.requestUri237 url: api.settings.url.self 243 238 } ); 244 239 request.done( function( data ) { … … 264 259 $( document ).trigger( 'customize-preview-menu-refreshed', [ eventParam ] ); 265 260 } ); 261 request.fail( function() { 262 api.preview.send( 'refresh' ); 263 } ); 266 264 }, 267 265 -
trunk/src/wp-includes/js/customize-preview.js
r36407 r36414 147 147 148 148 api.preview.bind( 'active', function() { 149 if ( api.settings.nonce ) { 150 api.preview.send( 'nonce', api.settings.nonce ); 151 } 149 api.preview.send( 'nonce', api.settings.nonce ); 152 150 153 151 api.preview.send( 'documentTitle', document.title ); … … 162 160 setting._dirty = false; 163 161 } ); 162 } ); 163 164 api.preview.bind( 'nonce-refresh', function( nonce ) { 165 $.extend( api.settings.nonce, nonce ); 164 166 } ); 165 167 -
trunk/tests/phpunit/tests/customize/manager.php
r36261 r36414 370 370 371 371 /** 372 * Test get_nonces() method. 373 * 374 * @see WP_Customize_Manager::get_nonces() 375 */ 376 function test_nonces() { 377 $nonces = $this->manager->get_nonces(); 378 $this->assertInternalType( 'array', $nonces ); 379 $this->assertArrayHasKey( 'save', $nonces ); 380 $this->assertArrayHasKey( 'preview', $nonces ); 381 382 add_filter( 'customize_refresh_nonces', array( $this, 'filter_customize_refresh_nonces' ), 10, 2 ); 383 $nonces = $this->manager->get_nonces(); 384 $this->assertArrayHasKey( 'foo', $nonces ); 385 $this->assertEquals( wp_create_nonce( 'foo' ), $nonces['foo'] ); 386 } 387 388 /** 389 * Filter for customize_refresh_nonces. 390 * 391 * @param array $nonces Nonces. 392 * @param WP_Customize_Manager $manager Manager. 393 * @return array Nonces. 394 */ 395 function filter_customize_refresh_nonces( $nonces, $manager ) { 396 $this->assertInstanceOf( 'WP_Customize_Manager', $manager ); 397 $nonces['foo'] = wp_create_nonce( 'foo' ); 398 return $nonces; 399 } 400 401 /** 372 402 * Test customize_pane_settings() method. 373 403 * … … 400 430 $this->assertArrayHasKey( 'save', $data['nonce'] ); 401 431 $this->assertArrayHasKey( 'preview', $data['nonce'] ); 432 } 433 434 /** 435 * Test customize_preview_settings() method. 436 * 437 * @see WP_Customize_Manager::customize_preview_settings() 438 */ 439 function test_customize_preview_settings() { 440 wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) ); 441 $this->manager->register_controls(); 442 $this->manager->prepare_controls(); 443 $this->manager->set_post_value( 'foo', 'bar' ); 444 $_POST['customize_messenger_channel'] = 'preview-0'; 445 446 ob_start(); 447 $this->manager->customize_preview_settings(); 448 $content = ob_get_clean(); 449 450 $this->assertEquals( 1, preg_match( '/var _wpCustomizeSettings = ({.+});/', $content, $matches ) ); 451 $settings = json_decode( $matches[1], true ); 452 453 $this->assertArrayHasKey( 'theme', $settings ); 454 $this->assertArrayHasKey( 'url', $settings ); 455 $this->assertArrayHasKey( 'channel', $settings ); 456 $this->assertArrayHasKey( 'activePanels', $settings ); 457 $this->assertArrayHasKey( 'activeSections', $settings ); 458 $this->assertArrayHasKey( 'activeControls', $settings ); 459 $this->assertArrayHasKey( 'nonce', $settings ); 460 $this->assertArrayHasKey( '_dirty', $settings ); 461 462 $this->assertArrayHasKey( 'preview', $settings['nonce'] ); 463 $this->assertEquals( array( 'foo' ), $settings['_dirty'] ); 402 464 } 403 465 -
trunk/tests/phpunit/tests/customize/nav-menus.php
r35242 r36414 648 648 $this->assertContains( 'renderNonceValue', $data ); 649 649 $this->assertContains( 'renderNoncePostKey', $data ); 650 $this->assertContains( 'requestUri', $data );651 $this->assertContains( 'theme', $data );652 $this->assertContains( 'previewCustomizeNonce', $data );653 650 $this->assertContains( 'navMenuInstanceArgs', $data ); 654 $this->assertContains( 'requestUri', $data ); 655 656 } 657 651 } 658 652 }
Note: See TracChangeset
for help on using the changeset viewer.