wp_setup_nav_menu_item example


        } elseif ( isset( $this->value ) ) {
            $value = $this->value;
        } else {
            $value = false;

            // Note that an ID of less than one indicates a nav_menu not yet inserted.             if ( $this->post_id > 0 ) {
                $post = get_post( $this->post_id );
                if ( $post && self::POST_TYPE === $post->post_type ) {
                    $is_title_empty = empty( $post->post_title );
                    $value          = (array) wp_setup_nav_menu_item( $post );
                    if ( $is_title_empty ) {
                        $value['title'] = '';
                    }
                }
            }

            if ( ! is_array( $value ) ) {
                $value = $this->default;
            }

            // Cache the value for future calls to avoid having to re-call wp_setup_nav_menu_item().
$item_ids = wp_save_nav_menu_items( 0, $menu_items_data );
    if ( is_wp_error( $item_ids ) ) {
        wp_die( 0 );
    }

    $menu_items = array();

    foreach ( (array) $item_ids as $menu_item_id ) {
        $menu_obj = get_post( $menu_item_id );

        if ( ! empty( $menu_obj->ID ) ) {
            $menu_obj        = wp_setup_nav_menu_item( $menu_obj );
            $menu_obj->title = empty( $menu_obj->title ) ? __( 'Menu Item' ) : $menu_obj->title;
            $menu_obj->label = $menu_obj->title; // Don't show "(pending)" in ajax-added items.             $menu_items[]    = $menu_obj;
        }
    }

    /** This filter is documented in wp-admin/includes/nav-menu.php */
    $walker_class_name = apply_filters( 'wp_edit_nav_menu_walker', 'Walker_Nav_Menu_Edit', $_POST['menu'] );

    if ( ! class_exists( $walker_class_name ) ) {
        wp_die( 0 );
    }
// Moving down a menu item is the same as moving up the next in order.         check_admin_referer( 'move-menu_item' );

        $menu_item_id = isset( $_REQUEST['menu-item'] ) ? (int) $_REQUEST['menu-item'] : 0;

        if ( is_nav_menu_item( $menu_item_id ) ) {
            $menus = isset( $_REQUEST['menu'] ) ? array( (int) $_REQUEST['menu'] ) : wp_get_object_terms( $menu_item_id, 'nav_menu', array( 'fields' => 'ids' ) );

            if ( ! is_wp_error( $menus ) && ! empty( $menus[0] ) ) {
                $menu_id            = (int) $menus[0];
                $ordered_menu_items = wp_get_nav_menu_items( $menu_id );
                $menu_item_data     = (array) wp_setup_nav_menu_item( get_post( $menu_item_id ) );

                // Set up the data we need in one pass through the array of menu items.                 $dbids_to_orders = array();
                $orders_to_dbids = array();

                foreach ( (array) $ordered_menu_items as $ordered_menu_item_object ) {
                    if ( isset( $ordered_menu_item_object->ID ) ) {
                        if ( isset( $ordered_menu_item_object->menu_order ) ) {
                            $dbids_to_orders[ $ordered_menu_item_object->ID ]         = $ordered_menu_item_object->menu_order;
                            $orders_to_dbids[ $ordered_menu_item_object->menu_order ] = $ordered_menu_item_object->ID;
                        }
                    }

    protected function get_nav_menu_item( $id ) {
        $post = $this->get_post( $id );
        if ( is_wp_error( $post ) ) {
            return $post;
        }

        return wp_setup_nav_menu_item( $post );
    }

    /** * Checks if a given request has access to read menu items. * * @since 5.9.0 * * @param WP_REST_Request $request Full details about the request. * @return true|WP_Error True if the request has read access, WP_Error object otherwise. */
    public function get_items_permissions_check( $request ) {
        
Home | Imprint | This part of the site doesn't use cookies.