get_registered_nav_menus example


    protected function handle_locations( $menu_id$request ) {
        if ( ! isset( $request['locations'] ) ) {
            return true;
        }

        $menu_locations = get_registered_nav_menus();
        $menu_locations = array_keys( $menu_locations );
        $new_locations  = array();
        foreach ( $request['locations'] as $location ) {
            if ( ! in_array( $location$menu_locations, true ) ) {
                return new WP_Error(
                    'rest_invalid_menu_location',
                    __( 'Invalid menu location.' ),
                    array(
                        'status'   => 400,
                        'location' => $location,
                    )
                );
/** * Determines whether a registered nav menu location has a menu assigned to it. * * @since 3.0.0 * * @param string $location Menu location identifier. * @return bool Whether location has a menu. */
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. */
// 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();


    public function enqueue_scripts() {
        wp_enqueue_style( 'customize-nav-menus' );
        wp_enqueue_script( 'customize-nav-menus' );

        $temp_nav_menu_setting      = new WP_Customize_Nav_Menu_Setting( $this->manager, 'nav_menu[-1]' );
        $temp_nav_menu_item_setting = new WP_Customize_Nav_Menu_Item_Setting( $this->manager, 'nav_menu_item[-1]' );

        $num_locations = count( get_registered_nav_menus() );

        if ( 1 === $num_locations ) {
            $locations_description = __( 'Your theme can display menus in one location.' );
        } else {
            /* translators: %s: Number of menu locations. */
            $locations_description = sprintf( _n( 'Your theme can display menus in %s location.', 'Your theme can display menus in %s locations.', $num_locations )number_format_i18n( $num_locations ) );
        }

        // Pass data to JS.         $settings = array(
            'allMenus'                 => wp_get_nav_menus(),
            
/** * Retrieves all menu locations, depending on user context. * * @since 5.9.0 * * @param WP_REST_Request $request Full details about the request. * @return WP_Error|WP_REST_Response Response object on success, or WP_Error object on failure. */
    public function get_items( $request ) {
        $data = array();

        foreach ( get_registered_nav_menus() as $name => $description ) {
            $location              = new stdClass();
            $location->name        = $name;
            $location->description = $description;

            $location      = $this->prepare_item_for_response( $location$request );
            $data[ $name ] = $this->prepare_response_for_collection( $location );
        }

        return rest_ensure_response( $data );
    }

    
/* translators: Hidden accessibility text. */
                                    __( '(opens in a new tab)' )
                                )
                            );
                            ?> </p> <# } else { #> <p><?php echo _x( 'Here&#8217;s where this menu appears. If you would like to change that, pick another location.', 'menu locations' ); ?></p> <# } #> </li> <?php foreach ( get_registered_nav_menus() as $location => $description ) : ?> <# elementId = _.uniqueId( 'customize-nav-menu-control-location-' ); #> <li class="customize-control customize-control-checkbox assigned-menu-location"> <span class="customize-inside-control-row"> <input id="{{ elementId }}" type="checkbox" data-menu-id="{{ data.menu_id }}" data-location-id="<?php echo esc_attr( $location ); ?>" class="menu-location" /> <label for="{{ elementId }}"> <?php echo $description; ?> <span class="theme-location-set"> <?php                                     printf(
                                        /* translators: %s: Menu name. */
                                        _x( '(Current: %s)', 'menu location' ),
                                        
Home | Imprint | This part of the site doesn't use cookies.