[wp-trac] [WordPress Trac] #30983: Missing Hook in wp_update_nav_menu_item function

WordPress Trac noreply at wordpress.org
Sun Jan 11 22:43:16 UTC 2015


#30983: Missing Hook in wp_update_nav_menu_item function
---------------------------+-----------------------------
 Reporter:  WPThemeTrends  |      Owner:
     Type:  defect (bug)   |     Status:  new
 Priority:  normal         |  Milestone:  Awaiting Review
Component:  Menus          |    Version:  4.1
 Severity:  normal         |   Keywords:
  Focuses:                 |
---------------------------+-----------------------------
 Hi,

 The function named "wp_update_nav_menu_item" contains an action at the end
 of the function ;
 {{{
 do_action( 'wp_update_nav_menu_item', $menu_id, $menu_item_db_id, $args );
 }}}
 However, this only fired if menu item updated. But this function used for
 making new items as well. At the code line "394" to "400" it can return
 after making new item. However, this time the hook is not fired. Code
 reference ;

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

 Code file ;

 https://developer.wordpress.org/reference/functions/wp_update_nav_menu_item/

 That code lines should be updated with that hook. Something like this ;


 {{{
 if ( ! $update ) {
         $post['ID'] = 0;
         $post['post_status'] = 'publish' == $args['menu-item-status'] ?
 'publish' : 'draft';
         $menu_item_db_id = wp_insert_post( $post );
         if ( ! $menu_item_db_id || is_wp_error( $menu_item_db_id ) ){
             do_action( 'wp_update_nav_menu_item', $menu_id,
 $menu_item_db_id, $args );
             return $menu_item_db_id;
         }
     }
 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/30983>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list