diff --git a/src/wp-includes/class-wp-customize-nav-menus.php b/src/wp-includes/class-wp-customize-nav-menus.php index fdf45e5229..9b24fa0b67 100644 --- a/src/wp-includes/class-wp-customize-nav-menus.php +++ b/src/wp-includes/class-wp-customize-nav-menus.php @@ -1265,14 +1265,14 @@ final class WP_Customize_Nav_Menus { * * @param string $nav_menu_content The HTML content for the navigation menu. * @param object $args An object containing wp_nav_menu() arguments. - * @return null + * @return string Nav menu HTML with selective refresh attributes added if partial can be refreshed. */ public function filter_wp_nav_menu( $nav_menu_content, $args ) { if ( isset( $args->customize_preview_nav_menus_args['can_partial_refresh'] ) && $args->customize_preview_nav_menus_args['can_partial_refresh'] ) { $attributes = sprintf( ' data-customize-partial-id="%s"', esc_attr( 'nav_menu_instance[' . $args->customize_preview_nav_menus_args['args_hmac'] . ']' ) ); $attributes .= ' data-customize-partial-type="nav_menu_instance"'; $attributes .= sprintf( ' data-customize-partial-placement-context="%s"', esc_attr( wp_json_encode( $args->customize_preview_nav_menus_args ) ) ); - $nav_menu_content = preg_replace( '#^(<\w+)#', '$1 ' . $attributes, $nav_menu_content, 1 ); + $nav_menu_content = preg_replace( '#^(<\w+)#', '$1 ' . str_replace( '\\', '\\\\', $attributes ), $nav_menu_content, 1 ); } return $nav_menu_content; } diff --git a/tests/phpunit/tests/customize/nav-menus.php b/tests/phpunit/tests/customize/nav-menus.php index 77116305e2..393790af43 100644 --- a/tests/phpunit/tests/customize/nav-menus.php +++ b/tests/phpunit/tests/customize/nav-menus.php @@ -861,19 +861,27 @@ class Test_WP_Customize_Nav_Menus extends WP_UnitTestCase { /** * Test the filter_wp_nav_menu method. * - * @see WP_Customize_Nav_Menus::filter_wp_nav_menu() + * @covers WP_Customize_Nav_Menus::filter_wp_nav_menu() + * @covers WP_Customize_Nav_Menus::filter_wp_nav_menu_args() */ function test_filter_wp_nav_menu() { do_action( 'customize_register', $this->wp_customize ); $menus = new WP_Customize_Nav_Menus( $this->wp_customize ); - $args = $menus->filter_wp_nav_menu_args( array( + $original_args = array( 'echo' => true, 'menu' => wp_create_nav_menu( 'Foo' ), 'fallback_cb' => 'wp_page_menu', 'walker' => '', 'items_wrap' => '