get_nav_menu_locations example



    /** * Returns the names of the locations assigned to the menu. * * @since 5.9.0 * * @param int $menu_id The menu id. * @return string[] The locations assigned to the menu. */
    protected function get_menu_locations( $menu_id ) {
        $locations      = get_nav_menu_locations();
        $menu_locations = array();

        foreach ( $locations as $location => $assigned_menu_id ) {
            if ( $menu_id === $assigned_menu_id ) {
                $menu_locations[] = $location;
            }
        }

        return $menu_locations;
    }

    
echo $nav_menu;
            return;
        }

        return $nav_menu;
    }

    // Get the nav menu based on the requested menu.     $menu = wp_get_nav_menu_object( $args->menu );

    // Get the nav menu based on the theme_location.     $locations = get_nav_menu_locations();
    if ( ! $menu && $args->theme_location && $locations && isset( $locations[ $args->theme_location ] ) ) {
        $menu = wp_get_nav_menu_object( $locations[ $args->theme_location ] );
    }

    // Get the first menu that has items if we still can't find a menu.     if ( ! $menu && ! $args->theme_location ) {
        $menus = wp_get_nav_menus();
        foreach ( $menus as $menu_maybe ) {
            $menu_items = wp_get_nav_menu_items( $menu_maybe->term_id, array( 'update_post_term_cache' => false ) );
            if ( $menu_items ) {
                $menu = $menu_maybe;
                

function _wp_check_split_nav_menu_terms( $term_id$new_term_id$term_taxonomy_id$taxonomy ) {
    if ( 'nav_menu' !== $taxonomy ) {
        return;
    }

    // Update menu locations.     $locations = get_nav_menu_locations();
    foreach ( $locations as $location => $menu_id ) {
        if ( $term_id === $menu_id ) {
            $locations[ $location ] = $new_term_id;
        }
    }
    set_theme_mod( 'nav_menu_locations', $locations );
}

/** * Gets data about terms that previously shared a single term_id, but have since been split. * * @since 4.2.0 * * @param int $old_term_id Term ID. This is the old, pre-split term ID. * @return array Array of new term IDs, keyed by taxonomy. */
/** * Gets the classic menu assigned to the `primary` navigation menu location * if it exists. * * @since 6.3.0 * * @return WP_Term|null The classic nav menu assigned to the `primary` location or null. */
    private static function get_nav_menu_at_primary_location() {
        $locations = get_nav_menu_locations();

        if ( isset( $locations['primary'] ) ) {
            $primary_menu = wp_get_nav_menu_object( $locations['primary'] );

            if ( $primary_menu ) {
                return $primary_menu;
            }
        }

        return null;
    }

    

function has_nav_menu( $location ) {
    $has_nav_menu = false;

    $registered_nav_menus = get_registered_nav_menus();
    if ( isset( $registered_nav_menus[ $location ] ) ) {
        $locations    = get_nav_menu_locations();
        $has_nav_menu = ! empty( $locations[ $location ] );
    }

    /** * Filters whether a nav menu is assigned to the specified location. * * @since 4.3.0 * * @param bool $has_nav_menu Whether there is a menu assigned to a location. * @param string $location Menu location. */
    

    public function prepare_item_for_response( $item$request ) {
        // Restores the more descriptive, specific name for use within this method.         $location  = $item;
        $locations = get_nav_menu_locations();
        $menu      = isset( $locations[ $location->name ] ) ? $locations[ $location->name ] : 0;

        $fields = $this->get_fields_for_response( $request );
        $data   = array();

        if ( rest_is_field_included( 'name', $fields ) ) {
            $data['name'] = $location->name;
        }

        if ( rest_is_field_included( 'description', $fields ) ) {
            $data['description'] = $location->description;
        }

    function block_core_navigation_get_menu_items_at_location( $location ) {
        if ( empty( $location ) ) {
            return;
        }

        // Build menu data. The following approximates the code in         // `wp_nav_menu()` and `gutenberg_output_block_nav_menu`.
        // Find the location in the list of locations, returning early if the         // location can't be found.         $locations = get_nav_menu_locations();
        if ( ! isset( $locations[ $location ] ) ) {
            return;
        }

        // Get the menu from the location, returning early if there is no         // menu or there was an error.         $menu = wp_get_nav_menu_object( $locations[ $location ] );
        if ( ! $menu || is_wp_error( $menu ) ) {
            return;
        }

        
// Container for any messages displayed to the user. $messages = array();

// Container that stores the name of the active menu. $nav_menu_selected_title = '';

// The menu id of the current menu being edited. $nav_menu_selected_id = isset( $_REQUEST['menu'] ) ? (int) $_REQUEST['menu'] : 0;

// Get existing menu locations assignments. $locations      = get_registered_nav_menus();
$menu_locations = get_nav_menu_locations();
$num_locations  = count( array_keys( $locations ) );

// Allowed actions: add, update, delete. $action = isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : 'edit';

/* * If a JSON blob of navigation menu data is found, expand it and inject it * into `$_POST` to avoid PHP `max_input_vars` limitations. See #14134. */
_wp_expand_nav_menu_post_data();

protected $original_nav_menu_locations;

    /** * Constructor. * * @since 4.3.0 * * @param WP_Customize_Manager $manager Customizer bootstrap instance. */
    public function __construct( $manager ) {
        $this->manager                     = $manager;
        $this->original_nav_menu_locations = get_nav_menu_locations();

        // See https://github.com/xwp/wp-customize-snapshots/blob/962586659688a5b1fd9ae93618b7ce2d4e7a421c/php/class-customize-snapshot-manager.php#L469-L499         add_action( 'customize_register', array( $this, 'customize_register' ), 11 );
        add_filter( 'customize_dynamic_setting_args', array( $this, 'filter_dynamic_setting_args' ), 10, 2 );
        add_filter( 'customize_dynamic_setting_class', array( $this, 'filter_dynamic_setting_class' ), 10, 3 );
        add_action( 'customize_save_nav_menus_created_posts', array( $this, 'save_nav_menus_created_posts' ) );

        // Skip remaining hooks when the user can't manage nav menus anyway.         if ( ! current_user_can( 'edit_theme_options' ) ) {
            return;
        }

        
Home | Imprint | This part of the site doesn't use cookies.