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

WP_Customize_Nav_Menu_Setting::filter_wp_get_nav_menus() public WP 4.3.0

Filters the wp_get_nav_menus() result to ensure the inserted menu object is included, and the deleted one is removed.

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

Хуков нет.

Возвращает

WP_Term[]. Array of menu objects.

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

$WP_Customize_Nav_Menu_Setting = new WP_Customize_Nav_Menu_Setting();
$WP_Customize_Nav_Menu_Setting->filter_wp_get_nav_menus( $menus, $args );
$menus(WP_Term[]) (обязательный)
An array of menu objects.
$args(массив) (обязательный)
An array of arguments used to retrieve menu objects.

Заметки

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

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

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

Код WP_Customize_Nav_Menu_Setting::filter_wp_get_nav_menus() WP 5.5.1

wp-includes/customize/class-wp-customize-nav-menu-setting.php
<?php
public function filter_wp_get_nav_menus( $menus, $args ) {
	if ( get_current_blog_id() !== $this->_previewed_blog_id ) {
		return $menus;
	}

	$setting_value = $this->value();
	$is_delete     = ( false === $setting_value );
	$index         = -1;

	// Find the existing menu item's position in the list.
	foreach ( $menus as $i => $menu ) {
		if ( (int) $this->term_id === (int) $menu->term_id || (int) $this->previous_term_id === (int) $menu->term_id ) {
			$index = $i;
			break;
		}
	}

	if ( $is_delete ) {
		// Handle deleted menu by removing it from the list.
		if ( -1 !== $index ) {
			array_splice( $menus, $index, 1 );
		}
	} else {
		// Handle menus being updated or inserted.
		$menu_obj = (object) array_merge(
			array(
				'term_id'          => $this->term_id,
				'term_taxonomy_id' => $this->term_id,
				'slug'             => sanitize_title( $setting_value['name'] ),
				'count'            => 0,
				'term_group'       => 0,
				'taxonomy'         => self::TAXONOMY,
				'filter'           => 'raw',
			),
			$setting_value
		);

		array_splice( $menus, $index, ( -1 === $index ? 0 : 1 ), array( $menu_obj ) );
	}

	// Make sure the menu objects get re-sorted after an update/insert.
	if ( ! $is_delete && ! empty( $args['orderby'] ) ) {
		$menus = wp_list_sort(
			$menus,
			array(
				$args['orderby'] => 'ASC',
			)
		);
	}
	// @todo Add support for $args['hide_empty'] === true.

	return $menus;
}