wp_admin_bar_new_content_menu

Add "Add New" menu.

Description

wp_admin_bar_new_content_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_new_content_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_new_content_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_new_content_menu( $wp_admin_bar ) { 
  2. $actions = array(); 
  3.  
  4. $cpts = (array) get_post_types( array( 'show_in_admin_bar' => true ), 'objects' ); 
  5.  
  6. if ( isset( $cpts['post'] ) && current_user_can( $cpts['post']->cap->create_posts ) ) 
  7. $actions[ 'post-new.php' ] = array( $cpts['post']->labels->name_admin_bar, 'new-post' ); 
  8.  
  9. if ( isset( $cpts['attachment'] ) && current_user_can( 'upload_files' ) ) 
  10. $actions[ 'media-new.php' ] = array( $cpts['attachment']->labels->name_admin_bar, 'new-media' ); 
  11.  
  12. if ( current_user_can( 'manage_links' ) ) 
  13. $actions[ 'link-add.php' ] = array( _x( 'Link', 'add new from admin bar' ), 'new-link' ); 
  14.  
  15. if ( isset( $cpts['page'] ) && current_user_can( $cpts['page']->cap->create_posts ) ) 
  16. $actions[ 'post-new.php?post_type=page' ] = array( $cpts['page']->labels->name_admin_bar, 'new-page' ); 
  17.  
  18. unset( $cpts['post'], $cpts['page'], $cpts['attachment'] ); 
  19.  
  20. // Add any additional custom post types. 
  21. foreach ( $cpts as $cpt ) { 
  22. if ( ! current_user_can( $cpt->cap->create_posts ) ) 
  23. continue; 
  24.  
  25. $key = 'post-new.php?post_type=' . $cpt->name; 
  26. $actions[ $key ] = array( $cpt->labels->name_admin_bar, 'new-' . $cpt->name ); 
  27. // Avoid clash with parent node and a 'content' post type. 
  28. if ( isset( $actions['post-new.php?post_type=content'] ) ) 
  29. $actions['post-new.php?post_type=content'][1] = 'add-new-content'; 
  30.  
  31. if ( current_user_can( 'create_users' ) || current_user_can( 'promote_users' ) ) 
  32. $actions[ 'user-new.php' ] = array( _x( 'User', 'add new from admin bar' ), 'new-user' ); 
  33.  
  34. if ( ! $actions ) 
  35. return; 
  36.  
  37. $title = '<span class="ab-icon"></span><span class="ab-label">' . _x( 'New', 'admin bar menu group label' ) . '</span>'; 
  38.  
  39. $wp_admin_bar->add_menu( array( 
  40. 'id' => 'new-content',  
  41. 'title' => $title,  
  42. 'href' => admin_url( current( array_keys( $actions ) ) ),  
  43. ) ); 
  44.  
  45. foreach ( $actions as $link => $action ) { 
  46. list( $title, $id ) = $action; 
  47.  
  48. $wp_admin_bar->add_menu( array( 
  49. 'parent' => 'new-content',  
  50. 'id' => $id,  
  51. 'title' => $title,  
  52. 'href' => admin_url( $link ) 
  53. ) );