GC_Customize_Nav_Menu_Setting::filter_nav_menu_options_value()

最后更新于:2021-11-27 06:12:04

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

Updates a nav_menu_options array.

参数

$nav_menu_options

(array) (Required) Array as returned by get_option( ‘nav_menu_options’ ).

$menu_id

(int) (Required) The term ID for the given menu.

$auto_add

(bool) (Required) Whether to auto-add or not.

响应

(array) (Maybe) modified nav_menu_otions array.

源文件

文件: gc-includes/customize/class-gc-customize-nav-menu-setting.php

	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;
	}