GC_Customize_Nav_Menus::filter_gc_nav_menu()

最后更新于:2021-11-27 04:11:08

GC_Customize_Nav_Menus::filter_gc_nav_menu( string$nav_menu_content, object$args)

Prepares gc_nav_menu() calls for partial refresh.

参数

$nav_menu_content

(string) (Required) The HTML content for the navigation menu.

$args

(object) (Required) An object containing gc_nav_menu() arguments.

响应

(string) Nav menu HTML with selective refresh attributes added if partial can be refreshed.

源文件

文件: gc-includes/class-gc-customize-nav-menus.php

	public function filter_gc_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( gc_json_encode( $args->customize_preview_nav_menus_args ) ) );
			$nav_menu_content = preg_replace( '#^(<w+)#', '$1 ' . str_replace( '\', '\\', $attributes ), $nav_menu_content, 1 );
		}
		return $nav_menu_content;
	}