From 83746331cfdf9612f819565d687b3b00b0752981 Mon Sep 17 00:00:00 2001 From: nacin Date: Tue, 27 Sep 2011 04:04:10 +0000 Subject: [PATCH] Cleanup in wp_admin_bar_new_content_menu. current() instead of array_shift(), remove unused index 1 from the arrays, remove ?post_type=post from the Post link. see #18197. git-svn-id: http://svn.automattic.com/wordpress/trunk@18788 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/admin-bar.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/wp-includes/admin-bar.php b/wp-includes/admin-bar.php index fc7643d01f..bdf95e1d9d 100644 --- a/wp-includes/admin-bar.php +++ b/wp-includes/admin-bar.php @@ -429,38 +429,38 @@ function wp_admin_bar_edit_menu( $wp_admin_bar ) { * @since 3.1.0 */ function wp_admin_bar_new_content_menu( $wp_admin_bar ) { - $primary = array(); - $secondary = array(); + $primary = $secondary = array(); foreach ( (array) get_post_types( array( 'show_in_admin_bar' => true ), 'objects' ) as $ptype_obj ) { if ( ! current_user_can( $ptype_obj->cap->edit_posts ) ) continue; - $primary[ 'post-new.php?post_type=' . $ptype_obj->name ] = array( $ptype_obj->labels->name_admin_bar, $ptype_obj->cap->edit_posts, 'new-' . $ptype_obj->name ); + $key = 'post' == $ptype_obj->name ? 'post-new.php' : 'post-new.php?post_type=' . $ptype_obj->name; + $primary[ $key ] = array( $ptype_obj->labels->name_admin_bar, 'new-' . $ptype_obj->name ); } if ( current_user_can( 'upload_files' ) ) - $primary[ 'media-new.php' ] = array( _x( 'Media', 'add new from admin bar' ), 'upload_files', 'new-media' ); + $primary[ 'media-new.php' ] = array( _x( 'Media', 'add new from admin bar' ), 'new-media' ); if ( current_user_can( 'manage_links' ) ) - $primary[ 'link-add.php' ] = array( _x( 'Link', 'add new from admin bar' ), 'manage_links', 'new-link' ); + $primary[ 'link-add.php' ] = array( _x( 'Link', 'add new from admin bar' ), 'new-link' ); if ( current_user_can( 'create_users' ) || current_user_can( 'promote_users' ) ) - $secondary[ 'user-new.php' ] = array( _x( 'User', 'add new from admin bar' ), 'create_users', 'new-user' ); + $secondary[ 'user-new.php' ] = array( _x( 'User', 'add new from admin bar' ), 'new-user' ); if ( ! is_multisite() && current_user_can( 'install_themes' ) ) - $secondary[ 'theme-install.php' ] = array( _x( 'Theme', 'add new from admin bar' ), 'install_themes', 'new-theme' ); + $secondary[ 'theme-install.php' ] = array( _x( 'Theme', 'add new from admin bar' ), 'new-theme' ); if ( ! is_multisite() && current_user_can( 'install_plugins' ) ) - $secondary[ 'plugin-install.php' ] = array( _x( 'Plugin', 'add new from admin bar' ), 'install_plugins', 'new-plugin' ); + $secondary[ 'plugin-install.php' ] = array( _x( 'Plugin', 'add new from admin bar' ), 'new-plugin' ); - if ( empty( $primary ) && empty( $secondary ) ) + if ( ! $primary && ! $secondary ) return; $wp_admin_bar->add_menu( array( 'id' => 'new-content', 'title' => _x( 'Add New', 'admin bar menu group label' ), - 'href' => admin_url( array_shift( array_keys( $primary ) ) ), + 'href' => admin_url( current( array_keys( $primary ) ) ), ) ); $items = array( @@ -484,7 +484,7 @@ function wp_admin_bar_new_content_menu( $wp_admin_bar ) { foreach ( $actions as $link => $action ) { $wp_admin_bar->add_menu( array( 'parent' => $parent, - 'id' => $action[2], + 'id' => $action[1], 'title' => $action[0], 'href' => admin_url( $link ) ) );