From 3c0e4d3860949de4671061c402a609acbd5463ea Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Wed, 8 Jul 2015 20:17:52 +0000 Subject: [PATCH] Customizer: Prevent loss of `walker` and `fallback_cb` args for `wp_nav_menu`. These args only need to be cleared out when exported to JavaScript, when they are not JSON-serializable. So the filter now clears these when gathering args for exporting to JS, but otherwise now leaves the original values to be passed through to `wp_nav_menu()`. Fixes #32781. git-svn-id: https://develop.svn.wordpress.org/trunk@33131 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class-wp-customize-nav-menus.php | 12 +++++++----- tests/phpunit/tests/customize/nav-menus.php | 10 +++++++--- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/wp-includes/class-wp-customize-nav-menus.php b/src/wp-includes/class-wp-customize-nav-menus.php index e7b7e0f505..c13ed93ba7 100644 --- a/src/wp-includes/class-wp-customize-nav-menus.php +++ b/src/wp-includes/class-wp-customize-nav-menus.php @@ -771,15 +771,17 @@ final class WP_Customize_Nav_Menus { ); $args['can_partial_refresh'] = $can_partial_refresh; + $hashed_args = $args; + if ( ! $can_partial_refresh ) { - $args['fallback_cb'] = ''; - $args['walker'] = ''; + $hashed_args['fallback_cb'] = ''; + $hashed_args['walker'] = ''; } - ksort( $args ); - $args['args_hash'] = $this->hash_nav_menu_args( $args ); + ksort( $hashed_args ); + $hashed_args['args_hash'] = $this->hash_nav_menu_args( $hashed_args ); - $this->preview_nav_menu_instance_args[ $this->preview_nav_menu_instance_number ] = $args; + $this->preview_nav_menu_instance_args[ $this->preview_nav_menu_instance_number ] = $hashed_args; return $args; } diff --git a/tests/phpunit/tests/customize/nav-menus.php b/tests/phpunit/tests/customize/nav-menus.php index 7c0ee3d039..616bf0b75c 100644 --- a/tests/phpunit/tests/customize/nav-menus.php +++ b/tests/phpunit/tests/customize/nav-menus.php @@ -358,7 +358,6 @@ class Test_WP_Customize_Nav_Menus extends WP_UnitTestCase { $expected = array( 'echo', - 'args_hash', 'can_partial_refresh', 'fallback_cb', 'instance_number', @@ -370,9 +369,14 @@ class Test_WP_Customize_Nav_Menus extends WP_UnitTestCase { 'walker' => new Walker_Nav_Menu(), ) ); $this->assertEqualSets( $expected, array_keys( $results ) ); - $this->assertEquals( '', $results['fallback_cb'] ); - $this->assertEquals( '', $results['walker'] ); + $this->assertEquals( 'wp_page_menu', $results['fallback_cb'] ); $this->assertEquals( 0, $results['can_partial_refresh'] ); + + $this->assertNotEmpty( $menus->preview_nav_menu_instance_args[ $results['instance_number'] ] ); + $preview_nav_menu_instance_args = $menus->preview_nav_menu_instance_args[ $results['instance_number'] ]; + $this->assertEquals( '', $preview_nav_menu_instance_args['fallback_cb'] ); + $this->assertEquals( '', $preview_nav_menu_instance_args['walker'] ); + $this->assertNotEmpty( $preview_nav_menu_instance_args['args_hash'] ); } /**