Make WordPress Core


Ignore:
Timestamp:
08/02/2017 05:10:05 AM (9 years ago)
Author:
westonruter
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-customize-nav-menus.php

    r41162 r41204  
    12661266         * @param string $nav_menu_content The HTML content for the navigation menu.
    12671267         * @param object $args             An object containing wp_nav_menu() arguments.
    1268          * @return null
     1268         * @return string Nav menu HTML with selective refresh attributes added if partial can be refreshed.
    12691269         */
    12701270        public function filter_wp_nav_menu( $nav_menu_content, $args ) {
    … …  
    12731273                        $attributes .= ' data-customize-partial-type="nav_menu_instance"';
    12741274                        $attributes .= sprintf( ' data-customize-partial-placement-context="%s"', esc_attr( wp_json_encode( $args->customize_preview_nav_menus_args ) ) );
    1275                         $nav_menu_content = preg_replace( '#^(<\w+)#', '$1 ' . $attributes, $nav_menu_content, 1 );
     1275                        $nav_menu_content = preg_replace( '#^(<\w+)#', '$1 ' . str_replace( '\\', '\\\\', $attributes ), $nav_menu_content, 1 );
    12761276                }
    12771277                return $nav_menu_content;
Note: See TracChangeset for help on using the changeset viewer.