ACF_Location_Nav_Menu::matchpublicACF 5.9.0

Matches the provided rule against the screen args returning a bool result.

Method of the class: ACF_Location_Nav_Menu{}

No Hooks.

Returns

true|false.

Usage

$ACF_Location_Nav_Menu = new ACF_Location_Nav_Menu();
$ACF_Location_Nav_Menu->match( $rule, $screen, $field_group );
$rule(array) (required)
The location rule.
$screen(array) (required)
The screen args.
$field_group(array) (required)
The field group settings.

Changelog

Since 5.9.0 Introduced.

ACF_Location_Nav_Menu::match() code ACF 6.8.8

public function match( $rule, $screen, $field_group ) {

	// Check screen args.
	if ( isset( $screen['nav_menu'] ) ) {
		$nav_menu = $screen['nav_menu'];
	} else {
		return false;
	}

	// Allow for "location/xxx" rule value.
	$rule['value'] = $rule['value'] ?? '';
	$bits          = explode( '/', $rule['value'] );
	if ( $bits[0] === 'location' ) {
		$location = $bits[1];

		// Get the map of menu locations [location => menu_id] and update $nav_menu to a location value.
		$menu_locations = get_nav_menu_locations();
		if ( isset( $menu_locations[ $location ] ) ) {
			$rule['value'] = $menu_locations[ $location ];
		}
	}

	// Compare rule against $nav_menu.
	return $this->compare_to_rule( $nav_menu, $rule );
}