From 260d9185018d3a58d407f35cf19c425f01599532 Mon Sep 17 00:00:00 2001 From: koopersmith Date: Mon, 10 Oct 2011 18:40:00 +0000 Subject: [PATCH] Improve admin bar item order for W menu, add new menu, and edit content item. see #18197. git-svn-id: http://svn.automattic.com/wordpress/trunk@18927 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/admin-bar.php | 53 +++++++++++++++++------------- wp-includes/class-wp-admin-bar.php | 4 +-- 2 files changed, 32 insertions(+), 25 deletions(-) diff --git a/wp-includes/admin-bar.php b/wp-includes/admin-bar.php index b6b1f6ff8e..a4d78e121f 100644 --- a/wp-includes/admin-bar.php +++ b/wp-includes/admin-bar.php @@ -117,6 +117,14 @@ function wp_admin_bar_wp_menu( $wp_admin_bar ) { ), ) ); + // Add WordPress.org link + $wp_admin_bar->add_menu( array( + 'parent' => 'wp-logo-secondary', + 'id' => 'wporg', + 'title' => __('WordPress.org'), + 'href' => 'http://wordpress.org', + ) ); + // Add codex link $wp_admin_bar->add_menu( array( 'parent' => 'wp-logo-secondary', @@ -125,14 +133,6 @@ function wp_admin_bar_wp_menu( $wp_admin_bar ) { 'href' => 'http://codex.wordpress.org', ) ); - // Add feedback link - $wp_admin_bar->add_menu( array( - 'parent' => 'wp-logo-secondary', - 'id' => 'feedback', - 'title' => __('Feedback'), - 'href' => 'http://wordpress.org/support/forum/requests-and-feedback', - ) ); - // Add forums link $wp_admin_bar->add_menu( array( 'parent' => 'wp-logo-secondary', @@ -141,12 +141,12 @@ function wp_admin_bar_wp_menu( $wp_admin_bar ) { 'href' => 'http://wordpress.org/support/', ) ); - // Add WordPress.org link + // Add feedback link $wp_admin_bar->add_menu( array( 'parent' => 'wp-logo-secondary', - 'id' => 'wporg', - 'title' => __('WordPress.org'), - 'href' => 'http://wordpress.org', + 'id' => 'feedback', + 'title' => __('Feedback'), + 'href' => 'http://wordpress.org/support/forum/requests-and-feedback', ) ); } @@ -465,12 +465,11 @@ function wp_admin_bar_edit_menu( $wp_admin_bar ) { function wp_admin_bar_new_content_menu( $wp_admin_bar ) { $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; + $cpts = (array) get_post_types( array( 'show_in_admin_bar' => true ), 'objects' ); - $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 ( isset( $cpts['post'] ) && current_user_can( $cpts['post']->cap->edit_posts ) ) { + $primary[ 'post-new.php' ] = array( $cpts['post']->labels->name_admin_bar, 'new-post' ); + unset( $cpts['post'] ); } if ( current_user_can( 'upload_files' ) ) @@ -479,15 +478,23 @@ function wp_admin_bar_new_content_menu( $wp_admin_bar ) { if ( current_user_can( 'manage_links' ) ) $primary[ 'link-add.php' ] = array( _x( 'Link', 'add new from admin bar' ), 'new-link' ); + if ( isset( $cpts['page'] ) && current_user_can( $cpts['page']->cap->edit_posts ) ) { + $primary[ 'post-new.php?post_type=page' ] = array( $cpts['page']->labels->name_admin_bar, 'new-page' ); + unset( $cpts['page'] ); + } + + // Add any additional custom post types. + foreach ( $cpts as $cpt ) { + if ( ! current_user_can( $cpt->cap->edit_posts ) ) + continue; + + $key = 'post-new.php?post_type=' . $cpt->name; + $primary[ $key ] = array( $cpt->labels->name_admin_bar, 'new-' . $cpt->name ); + } + if ( current_user_can( 'create_users' ) || current_user_can( 'promote_users' ) ) $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' ), 'new-theme' ); - - if ( ! is_multisite() && current_user_can( 'install_plugins' ) ) - $secondary[ 'plugin-install.php' ] = array( _x( 'Plugin', 'add new from admin bar' ), 'new-plugin' ); - if ( ! $primary && ! $secondary ) return; diff --git a/wp-includes/class-wp-admin-bar.php b/wp-includes/class-wp-admin-bar.php index 7c46a3643f..30fe18075e 100644 --- a/wp-includes/class-wp-admin-bar.php +++ b/wp-includes/class-wp-admin-bar.php @@ -183,10 +183,10 @@ class WP_Admin_Bar { add_action( 'admin_bar_menu', 'wp_admin_bar_updates_menu', 40 ); // Content related. - add_action( 'admin_bar_menu', 'wp_admin_bar_edit_menu', 50 ); add_action( 'admin_bar_menu', 'wp_admin_bar_comments_menu', 60 ); add_action( 'admin_bar_menu', 'wp_admin_bar_new_content_menu', 70 ); - add_action( 'admin_bar_menu', 'wp_admin_bar_shortlink_menu', 80 ); + add_action( 'admin_bar_menu', 'wp_admin_bar_edit_menu', 80 ); + add_action( 'admin_bar_menu', 'wp_admin_bar_shortlink_menu', 90 ); if ( ! is_admin() ) { add_action( 'admin_bar_menu', 'wp_admin_bar_search_menu', 100 );