WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru
функция не описана

WP_Customize_Nav_Menu_Item_Setting::filter_wp_get_nav_menu_items() public WP 4.3.0

Filters the wp_get_nav_menu_items() result to supply the previewed menu items.

Это метод класса: WP_Customize_Nav_Menu_Item_Setting{}

Хуков нет.

Возвращает

WP_Post[]. Array of menu item objects.

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

$WP_Customize_Nav_Menu_Item_Setting = new WP_Customize_Nav_Menu_Item_Setting();
$WP_Customize_Nav_Menu_Item_Setting->filter_wp_get_nav_menu_items( $items, $menu, $args );
$items(WP_Post[]) (обязательный)
An array of menu item post objects.
$menu(WP_Term) (обязательный)
The menu object.
$args(массив) (обязательный)
An array of arguments used to retrieve menu item objects.

Заметки

  • Смотрите: wp_get_nav_menu_items()

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

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

Код WP Customize Nav Menu Item Setting::filter wp get nav menu items: wp-includes/customize/class-wp-customize-nav-menu-item-setting.php WP 5.5.1

<?php
public function filter_wp_get_nav_menu_items( $items, $menu, $args ) {
	$this_item                = $this->value();
	$current_nav_menu_term_id = null;
	if ( isset( $this_item['nav_menu_term_id'] ) ) {
		$current_nav_menu_term_id = $this_item['nav_menu_term_id'];
		unset( $this_item['nav_menu_term_id'] );
	}

	$should_filter = (
		$menu->term_id === $this->original_nav_menu_term_id
		||
		$menu->term_id === $current_nav_menu_term_id
	);
	if ( ! $should_filter ) {
		return $items;
	}

	// Handle deleted menu item, or menu item moved to another menu.
	$should_remove = (
		false === $this_item
		||
		( isset( $this_item['_invalid'] ) && true === $this_item['_invalid'] )
		||
		(
			$this->original_nav_menu_term_id === $menu->term_id
			&&
			$current_nav_menu_term_id !== $this->original_nav_menu_term_id
		)
	);
	if ( $should_remove ) {
		$filtered_items = array();
		foreach ( $items as $item ) {
			if ( $item->db_id !== $this->post_id ) {
				$filtered_items[] = $item;
			}
		}
		return $filtered_items;
	}

	$mutated       = false;
	$should_update = (
		is_array( $this_item )
		&&
		$current_nav_menu_term_id === $menu->term_id
	);
	if ( $should_update ) {
		foreach ( $items as $item ) {
			if ( $item->db_id === $this->post_id ) {
				foreach ( get_object_vars( $this->value_as_wp_post_nav_menu_item() ) as $key => $value ) {
					$item->$key = $value;
				}
				$mutated = true;
			}
		}

		// Not found so we have to append it..
		if ( ! $mutated ) {
			$items[] = $this->value_as_wp_post_nav_menu_item();
		}
	}

	return $items;
}