Customize: For selective refresh of nav menus, prevent `preg_replace()` from dropping backslashes in JSON replaced into the `data-customize-partial-placement-context` HTML attribute.

Props dlh, westonruter.
Fixes #41488.

Built from https://develop.svn.wordpress.org/trunk@41204


git-svn-id: http://core.svn.wordpress.org/trunk@41044 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Weston Ruter 2017-08-02 05:11:44 +00:00
parent 0401cee8b3
commit eb658592df
2 changed files with 3 additions and 3 deletions

View File

@ -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;
}

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.9-alpha-41200';
$wp_version = '4.9-alpha-41204';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.