[wp-trac] [WordPress Trac] #40878: Adding menus route

WordPress Trac noreply at wordpress.org
Wed Nov 3 14:23:25 UTC 2021


#40878: Adding menus route
-------------------------------------------------+-------------------------
 Reporter:  dingo_d                              |       Owner:
                                                 |  spacedmonkey
     Type:  task (blessed)                       |      Status:  assigned
 Priority:  high                                 |   Milestone:  5.9
Component:  REST API                             |     Version:  4.7
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch has-unit-tests needs-dev-  |     Focuses:  rest-api
  note                                           |
-------------------------------------------------+-------------------------

Comment (by spacedmonkey):

 In my testing, I believe we also need to change the
 `wp_update_nav_menu_item` function a little as well.

 These lines
 {{{#!php
         if ( $menu_id && ( ! $update || ! is_object_in_term(
 $menu_item_db_id, 'nav_menu', (int) $menu->term_id ) ) ) {
                 wp_set_object_terms( $menu_item_db_id, array(
 $menu->term_id ), 'nav_menu' );
         }
 }}}

 Should be changed to

 {{{#!php
         if ( $menu_id && ( ! $update || ! is_object_in_term(
 $menu_item_db_id, 'nav_menu', (int) $menu->term_id ) ) ) {
                 $update_terms = wp_set_object_terms( $menu_item_db_id,
 array( $menu->term_id ), 'nav_menu' );
                 if( is_wp_error( $update_terms ) ) {
                     return $update_terms;
                 }

         }
 }}}

 Simply this should be changed
 {{{#!php
         if ( $update ) {
                 $post['ID']          = $menu_item_db_id;
                 $post['post_status'] = ( 'draft' === $args['menu-item-
 status'] ) ? 'draft' : 'publish';
                 wp_update_post( $post );
         }

 }}}

 To

 {{{#!php
         if ( $update ) {
                 $post['ID']          = $menu_item_db_id;
                 $post['post_status'] = ( 'draft' === $args['menu-item-
 status'] ) ? 'draft' : 'publish';
                 $update_post = wp_update_post( $post );
                 if( is_wp_error( $update_post ) ) {
                     return $update_post;
                 }
         }

 }}}


 This will mean that if terms / post fail to update, then we get an
 WP_Error back. This is clear for the REST API.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/40878#comment:58>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list