wp_admin_bar_edit_menu

Provide an edit link for posts and terms.

Description

wp_admin_bar_edit_menu( (WP_Admin_Bar) $wp_admin_bar ); 

Parameters (1)

0. $wp_admin_bar (WP_Admin_Bar)
The wp admin bar.

Usage

  1. if ( !function_exists( 'wp_admin_bar_edit_menu' ) ) { 
  2. require_once ABSPATH . WPINC . '/admin-bar.php'; 
  3.  
  4. // The wp admin bar. 
  5. $wp_admin_bar = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wp_admin_bar_edit_menu($wp_admin_bar); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/admin-bar.php  
  1. function wp_admin_bar_edit_menu( $wp_admin_bar ) { 
  2. global $tag, $wp_the_query; 
  3.  
  4. if ( is_admin() ) { 
  5. $current_screen = get_current_screen(); 
  6. $post = get_post(); 
  7.  
  8. if ( 'post' == $current_screen->base 
  9. && 'add' != $current_screen->action 
  10. && ( $post_type_object = get_post_type_object( $post->post_type ) ) 
  11. && current_user_can( 'read_post', $post->ID ) 
  12. && ( $post_type_object->public ) 
  13. && ( $post_type_object->show_in_admin_bar ) ) 
  14. if ( 'draft' == $post->post_status ) { 
  15. $preview_link = get_preview_post_link( $post ); 
  16. $wp_admin_bar->add_menu( array( 
  17. 'id' => 'preview',  
  18. 'title' => $post_type_object->labels->view_item,  
  19. 'href' => esc_url( $preview_link ),  
  20. 'meta' => array( 'target' => 'wp-preview-' . $post->ID ),  
  21. ) ); 
  22. } else { 
  23. $wp_admin_bar->add_menu( array( 
  24. 'id' => 'view',  
  25. 'title' => $post_type_object->labels->view_item,  
  26. 'href' => get_permalink( $post->ID ) 
  27. ) ); 
  28. } elseif ( 'edit' == $current_screen->base 
  29. && ( $post_type_object = get_post_type_object( $current_screen->post_type ) ) 
  30. && ( $post_type_object->public ) 
  31. && ( $post_type_object->show_in_admin_bar ) 
  32. && ( get_post_type_archive_link( $post_type_object->name ) ) 
  33. && ! ( 'post' === $post_type_object->name && 'posts' === get_option( 'show_on_front' ) ) ) 
  34. $wp_admin_bar->add_node( array( 
  35. 'id' => 'archive',  
  36. 'title' => $post_type_object->labels->view_items,  
  37. 'href' => get_post_type_archive_link( $current_screen->post_type ) 
  38. ) ); 
  39. } elseif ( 'term' == $current_screen->base 
  40. && isset( $tag ) && is_object( $tag ) && ! is_wp_error( $tag ) 
  41. && ( $tax = get_taxonomy( $tag->taxonomy ) ) 
  42. && $tax->public ) 
  43. $wp_admin_bar->add_menu( array( 
  44. 'id' => 'view',  
  45. 'title' => $tax->labels->view_item,  
  46. 'href' => get_term_link( $tag ) 
  47. ) ); 
  48. } else { 
  49. $current_object = $wp_the_query->get_queried_object(); 
  50.  
  51. if ( empty( $current_object ) ) 
  52. return; 
  53.  
  54. if ( ! empty( $current_object->post_type ) 
  55. && ( $post_type_object = get_post_type_object( $current_object->post_type ) ) 
  56. && current_user_can( 'edit_post', $current_object->ID ) 
  57. && $post_type_object->show_in_admin_bar 
  58. && $edit_post_link = get_edit_post_link( $current_object->ID ) ) 
  59. $wp_admin_bar->add_menu( array( 
  60. 'id' => 'edit',  
  61. 'title' => $post_type_object->labels->edit_item,  
  62. 'href' => $edit_post_link 
  63. ) ); 
  64. } elseif ( ! empty( $current_object->taxonomy ) 
  65. && ( $tax = get_taxonomy( $current_object->taxonomy ) ) 
  66. && current_user_can( 'edit_term', $current_object->term_id ) 
  67. && $edit_term_link = get_edit_term_link( $current_object->term_id, $current_object->taxonomy ) ) 
  68. $wp_admin_bar->add_menu( array( 
  69. 'id' => 'edit',  
  70. 'title' => $tax->labels->edit_item,  
  71. 'href' => $edit_term_link 
  72. ) );