WP_Customize_Nav_Menu_Setting::filter_wp_get_nav_menu_object() WordPress Method

The WP_Customize_Nav_Menu_Setting::filter_wp_get_nav_menu_object() method is used to filter the nav menu object before it is passed to the customizer. This is useful for manipulating the menu properties before they are sent to the customizer.

WP_Customize_Nav_Menu_Setting::filter_wp_get_nav_menu_object( object|null $menu_obj, string $menu_id ) #

Filters the wp_get_nav_menu_object() result to supply the previewed menu object.


Description

Requesting a nav_menu object by anything but ID is not supported.

Top ↑

See also


Top ↑

Parameters

$menu_obj

(object|null)(Required)Object returned by wp_get_nav_menu_object().

$menu_id

(string)(Required)ID of the nav_menu term. Requests by slug or name will be ignored.


Top ↑

Return

(object|null)


Top ↑

Source

File: wp-includes/customize/class-wp-customize-nav-menu-setting.php

	public function filter_wp_get_nav_menu_object( $menu_obj, $menu_id ) {
		$ok = (
			get_current_blog_id() === $this->_previewed_blog_id
			&&
			is_int( $menu_id )
			&&
			$menu_id === $this->term_id
		);
		if ( ! $ok ) {
			return $menu_obj;
		}

		$setting_value = $this->value();

		// Handle deleted menus.
		if ( false === $setting_value ) {
			return false;
		}

		// Handle sanitization failure by preventing short-circuiting.
		if ( null === $setting_value ) {
			return $menu_obj;
		}

		$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
		);

		return $menu_obj;
	}


Top ↑

Changelog

Changelog
VersionDescription
4.3.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.