WP_Customize_Nav_Menus::filter_wp_nav_menu_args()publicWP 4.3.0

Keeps track of the arguments that are being passed to wp_nav_menu().

Метод класса: WP_Customize_Nav_Menus{}

Хуков нет.

Возвращает

Массив. Arguments.

Использование

$WP_Customize_Nav_Menus = new WP_Customize_Nav_Menus();
$WP_Customize_Nav_Menus->filter_wp_nav_menu_args( $args );
$args(массив) (обязательный)
An array containing wp_nav_menu() arguments.

Заметки

Список изменений

С версии 4.3.0 Введена.

Код WP_Customize_Nav_Menus::filter_wp_nav_menu_args() WP 6.5.2

public function filter_wp_nav_menu_args( $args ) {
	/*
	 * The following conditions determine whether or not this instance of
	 * wp_nav_menu() can use selective refreshed. A wp_nav_menu() can be
	 * selective refreshed if...
	 */
	$can_partial_refresh = (
		// ...if wp_nav_menu() is directly echoing out the menu (and thus isn't manipulating the string after generated),
		! empty( $args['echo'] )
		&&
		// ...and if the fallback_cb can be serialized to JSON, since it will be included in the placement context data,
		( empty( $args['fallback_cb'] ) || is_string( $args['fallback_cb'] ) )
		&&
		// ...and if the walker can also be serialized to JSON, since it will be included in the placement context data as well,
		( empty( $args['walker'] ) || is_string( $args['walker'] ) )
		// ...and if it has a theme location assigned or an assigned menu to display,
		&& (
			! empty( $args['theme_location'] )
			||
			( ! empty( $args['menu'] ) && ( is_numeric( $args['menu'] ) || is_object( $args['menu'] ) ) )
		)
		&&
		// ...and if the nav menu would be rendered with a wrapper container element (upon which to attach data-* attributes).
		(
			! empty( $args['container'] )
			||
			( isset( $args['items_wrap'] ) && str_starts_with( $args['items_wrap'], '<' ) )
		)
	);
	$args['can_partial_refresh'] = $can_partial_refresh;

	$exported_args = $args;

	// Empty out args which may not be JSON-serializable.
	if ( ! $can_partial_refresh ) {
		$exported_args['fallback_cb'] = '';
		$exported_args['walker']      = '';
	}

	/*
	 * Replace object menu arg with a term_id menu arg, as this exports better
	 * to JS and is easier to compare hashes.
	 */
	if ( ! empty( $exported_args['menu'] ) && is_object( $exported_args['menu'] ) ) {
		$exported_args['menu'] = $exported_args['menu']->term_id;
	}

	ksort( $exported_args );
	$exported_args['args_hmac'] = $this->hash_nav_menu_args( $exported_args );

	$args['customize_preview_nav_menus_args']                            = $exported_args;
	$this->preview_nav_menu_instance_args[ $exported_args['args_hmac'] ] = $exported_args;
	return $args;
}