Ticket #35617: 35617.2.diff
| File 35617.2.diff, 10.6 KB (added by , 10 years ago) |
|---|
-
src/wp-admin/js/customize-controls.js
diff --git src/wp-admin/js/customize-controls.js src/wp-admin/js/customize-controls.js index 4901b56..caf296a 100644
3375 3375 api.bind( 'nonce-refresh', function( nonce ) { 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 3380 3381 // Create Settings -
src/wp-includes/class-wp-customize-manager.php
diff --git src/wp-includes/class-wp-customize-manager.php src/wp-includes/class-wp-customize-manager.php index aa73ed7..48ccc80 100644
final class WP_Customize_Manager { 801 801 */ 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 818 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 819 foreach ( $this->panels as $panel_id => $panel ) { 819 820 if ( $panel->check_capabilities() ) { 820 821 $settings['activePanels'][ $panel_id ] = $panel->active(); … … final class WP_Customize_Manager { 1025 1026 wp_send_json_error( 'not_preview' ); 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 1046 1032 /** … … final class WP_Customize_Manager { 1636 1622 } 1637 1623 1638 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; 1648 } 1649 1650 /** 1639 1651 * Print JavaScript settings for parent window. 1640 1652 * 1641 1653 * @since 4.4.0 … … final class WP_Customize_Manager { 1695 1707 ), 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(), 1704 1713 ); -
src/wp-includes/class-wp-customize-nav-menus.php
diff --git src/wp-includes/class-wp-customize-nav-menus.php src/wp-includes/class-wp-customize-nav-menus.php index 2c90548..ec92d58 100644
final class WP_Customize_Nav_Menus { 939 939 'renderQueryVar' => self::RENDER_QUERY_VAR, 940 940 'renderNonceValue' => wp_create_nonce( self::RENDER_AJAX_ACTION ), 941 941 '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 942 'navMenuInstanceArgs' => $this->preview_nav_menu_instance_args, 949 943 'l10n' => array( 950 944 'editNavMenuItemTooltip' => __( 'Shift-click to edit this menu item.' ), -
src/wp-includes/js/customize-preview-nav-menus.js
diff --git src/wp-includes/js/customize-preview-nav-menus.js src/wp-includes/js/customize-preview-nav-menus.js index fe5f305..5441b86 100644
13 13 renderQueryVar: null, 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: {} 24 19 }; … … 200 195 menuId = parseInt( menuId, 10 ); 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'; 210 205 … … 239 234 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 ) { 245 240 // If the menu is now not visible, refresh since the page layout may have changed. … … 263 258 container.removeClass( 'customize-partial-refreshing' ); 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 268 266 refreshMenuInstanceDebounced : function( instanceNumber ) { -
src/wp-includes/js/customize-preview.js
diff --git src/wp-includes/js/customize-preview.js src/wp-includes/js/customize-preview.js index 1d18027..b6da775 100644
146 146 }); 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 ); 154 152 }); … … 163 161 } ); 164 162 } ); 165 163 164 api.preview.bind( 'nonce-refresh', function( nonce ) { 165 $.extend( api.settings.nonce, nonce ); 166 } ); 167 166 168 /* 167 169 * Send a message to the parent customize frame with a list of which 168 170 * containers and controls are active. -
tests/phpunit/tests/customize/manager.php
diff --git tests/phpunit/tests/customize/manager.php tests/phpunit/tests/customize/manager.php index e787cfa..4cf8d01 100644
class Tests_WP_Customize_Manager extends WP_UnitTestCase { 369 369 } 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 * 374 404 * @see WP_Customize_Manager::customize_pane_settings() … … class Tests_WP_Customize_Manager extends WP_UnitTestCase { 402 432 } 403 433 404 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'] ); 464 } 465 466 /** 405 467 * @ticket 33552 406 468 */ 407 469 function test_customize_loaded_components_filter() { -
tests/phpunit/tests/customize/nav-menus.php
diff --git tests/phpunit/tests/customize/nav-menus.php tests/phpunit/tests/customize/nav-menus.php index dd620c3..2969a2d 100644
class Test_WP_Customize_Nav_Menus extends WP_UnitTestCase { 647 647 $this->assertContains( 'renderQueryVar', $data ); 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 651 } 657 658 652 }