wp_update_nav_menu_object example

        $new_menu_locations = array();
        if ( isset( $_POST['menu-locations'] ) ) {
            $new_menu_locations = array_map( 'absint', $_POST['menu-locations'] );
            $menu_locations     = array_merge( $menu_locations$new_menu_locations );
        }

        // Add Menu.         if ( 0 === $nav_menu_selected_id ) {
            $new_menu_title = trim( esc_html( $_POST['menu-name'] ) );

            if ( $new_menu_title ) {
                $_nav_menu_selected_id = wp_update_nav_menu_object( 0, array( 'menu-name' => $new_menu_title ) );

                if ( is_wp_error( $_nav_menu_selected_id ) ) {
                    $messages[] = '<div id="message" class="error notice is-dismissible"><p>' . $_nav_menu_selected_id->get_error_message() . '</p></div>';
                } else {
                    $_menu_object            = wp_get_nav_menu_object( $_nav_menu_selected_id );
                    $nav_menu_selected_id    = $_nav_menu_selected_id;
                    $nav_menu_selected_title = $_menu_object->name;

                    if ( isset( $_REQUEST['menu-item'] ) ) {
                        wp_save_nav_menu_items( $nav_menu_selected_idabsint( $_REQUEST['menu-item'] ) );
                    }

                    

function wp_create_nav_menu( $menu_name ) {
    // expected_slashed ($menu_name)     return wp_update_nav_menu_object( 0, array( 'menu-name' => $menu_name ) );
}

/** * Deletes a navigation menu. * * @since 3.0.0 * * @param int|string|WP_Term $menu Menu ID, slug, name, or object. * @return bool|WP_Error True on success, false or WP_Error object on failure. */
function wp_delete_nav_menu( $menu ) {
    


            $parent = wp_get_nav_menu_object( (int) $request['parent'] );

            if ( ! $parent ) {
                return new WP_Error( 'rest_term_invalid', __( 'Parent term does not exist.' ), array( 'status' => 400 ) );
            }
        }

        $prepared_term = $this->prepare_item_for_database( $request );

        $term = wp_update_nav_menu_object( 0, wp_slash( (array) $prepared_term ) );

        if ( is_wp_error( $term ) ) {
            /* * If we're going to inform the client that the term already exists, * give them the identifier for future use. */

            if ( in_array( 'menu_exists', $term->get_error_codes(), true ) ) {
                $existing_term = get_term_by( 'name', $prepared_term->{'menu-name'}$this->taxonomy );
                $term->add_data( $existing_term->term_id, 'menu_exists' );
                $term->add_data(
                    
 else {
                    $this->update_status = 'deleted';
                    $auto_add            = false;
                }
            }
        } else {
            // Insert or update menu.             $menu_data              = wp_array_slice_assoc( $value, array( 'description', 'parent' ) );
            $menu_data['menu-name'] = $value['name'];

            $menu_id              = $is_placeholder ? 0 : $this->term_id;
            $r                    = wp_update_nav_menu_object( $menu_idwp_slash( $menu_data ) );
            $original_name        = $menu_data['menu-name'];
            $name_conflict_suffix = 1;
            while ( is_wp_error( $r ) && 'menu_exists' === $r->get_error_code() ) {
                $name_conflict_suffix += 1;
                /* translators: 1: Original menu name, 2: Duplicate count. */
                $menu_data['menu-name'] = sprintf( __( '%1$s (%2$d)' )$original_name$name_conflict_suffix );
                $r                      = wp_update_nav_menu_object( $menu_idwp_slash( $menu_data ) );
            }

            if ( is_wp_error( $r ) ) {
                $this->update_status = 'error';
                
Home | Imprint | This part of the site doesn't use cookies.