-function wp_admin_bar_edit_menu () {
- global $wp_admin_bar;
-
- $current_object = get_queried_object();
-
- if ( empty($current_object) )
- return;
-
- if ( ! empty( $current_object->post_type ) && ( $post_type_object = get_post_type_object( $current_object->post_type ) ) && current_user_can( $post_type_object->cap->edit_post, $current_object->ID ) && $post_type_object->show_ui ) {
- $wp_admin_bar->add_menu( array( 'id' => 'edit', 'title' => $post_type_object->labels->edit_item, 'href' => get_edit_post_link( $current_object->ID ) ) );
- } elseif ( ! empty( $current_object->taxonomy ) && ( $tax = get_taxonomy( $current_object->taxonomy ) ) && current_user_can( $tax->cap->edit_terms ) && $tax->show_ui ) {
- $wp_admin_bar->add_menu( array( 'id' => 'edit', 'title' => $tax->labels->edit_item, 'href' => get_edit_term_link( $current_object->term_id, $current_object->taxonomy ) ) );
+function wp_admin_bar_edit_menu( $wp_admin_bar ) {
+ global $tag, $wp_the_query;
+
+ if ( is_admin() ) {
+ $current_screen = get_current_screen();
+ $post = get_post();
+
+ if ( 'post' == $current_screen->base
+ && 'add' != $current_screen->action
+ && ( $post_type_object = get_post_type_object( $post->post_type ) )
+ && current_user_can( 'read_post', $post->ID )
+ && ( $post_type_object->public )
+ && ( $post_type_object->show_in_admin_bar ) )
+ {
+ if( 'draft' == $post->post_status ) {
+ $preview_link = set_url_scheme( get_permalink( $post->ID ) );
+ /** This filter is documented in wp-admin/includes/meta-boxes.php */
+ $preview_link = apply_filters( 'preview_post_link', add_query_arg( 'preview', 'true', $preview_link ), $post );
+ $wp_admin_bar->add_menu( array(
+ 'id' => 'preview',
+ 'title' => $post_type_object->labels->view_item,
+ 'href' => esc_url( $preview_link ),
+ 'meta' => array( 'target' => 'wp-preview-' . $post->ID ),
+ ) );
+ } else {
+ $wp_admin_bar->add_menu( array(
+ 'id' => 'view',
+ 'title' => $post_type_object->labels->view_item,
+ 'href' => get_permalink( $post->ID )
+ ) );
+ }
+ } elseif ( 'edit-tags' == $current_screen->base
+ && isset( $tag ) && is_object( $tag )
+ && ( $tax = get_taxonomy( $tag->taxonomy ) )
+ && $tax->public )
+ {
+ $wp_admin_bar->add_menu( array(
+ 'id' => 'view',
+ 'title' => $tax->labels->view_item,
+ 'href' => get_term_link( $tag )
+ ) );
+ }
+ } else {
+ $current_object = $wp_the_query->get_queried_object();
+
+ if ( empty( $current_object ) )
+ return;
+
+ if ( ! empty( $current_object->post_type )
+ && ( $post_type_object = get_post_type_object( $current_object->post_type ) )
+ && current_user_can( 'edit_post', $current_object->ID )
+ && $post_type_object->show_ui && $post_type_object->show_in_admin_bar
+ && $edit_post_link = get_edit_post_link( $current_object->ID ) )
+ {
+ $wp_admin_bar->add_menu( array(
+ 'id' => 'edit',
+ 'title' => $post_type_object->labels->edit_item,
+ 'href' => $edit_post_link
+ ) );
+ } elseif ( ! empty( $current_object->taxonomy )
+ && ( $tax = get_taxonomy( $current_object->taxonomy ) )
+ && current_user_can( $tax->cap->edit_terms )
+ && $tax->show_ui
+ && $edit_term_link = get_edit_term_link( $current_object->term_id, $current_object->taxonomy ) )
+ {
+ $wp_admin_bar->add_menu( array(
+ 'id' => 'edit',
+ 'title' => $tax->labels->edit_item,
+ 'href' => $edit_term_link
+ ) );
+ }