WP_Customize_Nav_Menu_Setting::filter_nav_menu_options_value( array $nav_menu_options, int $menu_id, bool $auto_add ): array

Updates a nav_menu_options array.

Description

See also

Parameters

$nav_menu_optionsarrayrequired
Array as returned by get_option( 'nav_menu_options' ).
$menu_idintrequired
The term ID for the given menu.
$auto_addboolrequired
Whether to auto-add or not.

Return

array (Maybe) modified nav_menu_options array.

Source

protected function filter_nav_menu_options_value( $nav_menu_options, $menu_id, $auto_add ) {
	$nav_menu_options = (array) $nav_menu_options;
	if ( ! isset( $nav_menu_options['auto_add'] ) ) {
		$nav_menu_options['auto_add'] = array();
	}

	$i = array_search( $menu_id, $nav_menu_options['auto_add'], true );

	if ( $auto_add && false === $i ) {
		array_push( $nav_menu_options['auto_add'], $this->term_id );
	} elseif ( ! $auto_add && false !== $i ) {
		array_splice( $nav_menu_options['auto_add'], $i, 1 );
	}

	return $nav_menu_options;
}

Changelog

VersionDescription
4.3.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.