| 1272 | | $attributes = sprintf( ' data-customize-partial-id="%s"', esc_attr( 'nav_menu_instance[' . $args->customize_preview_nav_menus_args['args_hmac'] . ']' ) ); |
| 1273 | | $attributes .= ' data-customize-partial-type="nav_menu_instance"'; |
| 1274 | | $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 ); |
| | 1272 | // Inject attributes with preg_replace() first to avoid mangling namespaces. |
| | 1273 | $nav_menu_content = preg_replace( |
| | 1274 | '#^(<\w+)#', |
| | 1275 | '$1 data-customize-partial-id="" data-customize-partial-type="" data-customize-partial-placement-context=""', |
| | 1276 | $nav_menu_content, |
| | 1277 | 1 |
| | 1278 | ); |
| | 1279 | |
| | 1280 | // Could use sprintf(), but it risks colliding with placeholder-like strings in the HTML. |
| | 1281 | $nav_menu_content = str_replace( |
| | 1282 | array( |
| | 1283 | 'data-customize-partial-id=""', |
| | 1284 | 'data-customize-partial-type=""', |
| | 1285 | 'data-customize-partial-placement-context=""', |
| | 1286 | ), |
| | 1287 | array( |
| | 1288 | sprintf( 'data-customize-partial-id="%s"', esc_attr( 'nav_menu_instance[' . $args->customize_preview_nav_menus_args['args_hmac'] . ']' ) ), |
| | 1289 | 'data-customize-partial-type="nav_menu_instance"', |
| | 1290 | sprintf( 'data-customize-partial-placement-context="%s"', esc_attr( wp_json_encode( $args->customize_preview_nav_menus_args ) ) ), |
| | 1291 | ), |
| | 1292 | $nav_menu_content |
| | 1293 | ); |