From 71c2782b1ce637eef5534e8a02417d392146c1ae Mon Sep 17 00:00:00 2001
From: nacin <nacin@1a063a9b-81f0-0310-95a4-ce76da25c4cd>
Date: Wed, 8 Jun 2011 16:49:27 +0000
Subject: [PATCH] Admin Bar: Add View Site/Dashboard links, 'View X' links in
 the admin, 'View' action link for terms. New custom taxonomy string:
 view_item, defaulting to 'View Tag' and View Category'. fixes #17705.

git-svn-id: http://svn.automattic.com/wordpress/trunk@18194 1a063a9b-81f0-0310-95a4-ce76da25c4cd
---
 .../includes/class-wp-terms-list-table.php    |  1 +
 wp-includes/admin-bar.php                     | 77 ++++++++++++++++---
 wp-includes/class-wp-admin-bar.php            |  1 +
 wp-includes/taxonomy.php                      |  1 +
 4 files changed, 69 insertions(+), 11 deletions(-)

diff --git a/wp-admin/includes/class-wp-terms-list-table.php b/wp-admin/includes/class-wp-terms-list-table.php
index db8b031abc..f9b3d59b12 100644
--- a/wp-admin/includes/class-wp-terms-list-table.php
+++ b/wp-admin/includes/class-wp-terms-list-table.php
@@ -261,6 +261,7 @@ class WP_Terms_List_Table extends WP_List_Table {
 		}
 		if ( current_user_can( $tax->cap->delete_terms ) && $tag->term_id != $default_term )
 			$actions['delete'] = "<a class='delete-tag' href='" . wp_nonce_url( "edit-tags.php?action=delete&amp;taxonomy=$taxonomy&amp;tag_ID=$tag->term_id", 'delete-tag_' . $tag->term_id ) . "'>" . __( 'Delete' ) . "</a>";
+		$actions['view'] = '<a href="' . get_term_link( $tag ) . '">' . __( 'View' ) . '</a>';
 
 		$actions = apply_filters( 'tag_row_actions', $actions, $tag );
 		$actions = apply_filters( "{$taxonomy}_row_actions", $actions, $tag );
diff --git a/wp-includes/admin-bar.php b/wp-includes/admin-bar.php
index 7a80789c23..1375d2419a 100644
--- a/wp-includes/admin-bar.php
+++ b/wp-includes/admin-bar.php
@@ -89,14 +89,24 @@ function wp_admin_bar_my_account_menu( $wp_admin_bar ) {
 
 		/* Add the "My Account" sub menus */
 		$wp_admin_bar->add_menu( array( 'parent' => $id, 'title' => __( 'Edit My Profile' ), 'href' => get_edit_profile_url( $user_id ) ) );
-		if ( is_multisite() )
-			$wp_admin_bar->add_menu( array( 'parent' => $id, 'title' => __( 'Dashboard' ), 'href' => get_dashboard_url( $user_id ) ) );
-		else
-			$wp_admin_bar->add_menu( array( 'parent' => $id, 'title' => __( 'Dashboard' ), 'href' => admin_url() ) );
 		$wp_admin_bar->add_menu( array( 'parent' => $id, 'title' => __( 'Log Out' ), 'href' => wp_logout_url() ) );
 	}
 }
 
+/**
+ * Add the "Dashboard"/"View Site" menu.
+ *
+ * @since 3.2.0
+ */
+function wp_admin_bar_dashboard_view_site_menu( $wp_admin_bar ) {
+	if ( is_admin() )
+		$wp_admin_bar->add_menu( array( 'title' => __( 'Visit Site' ), 'href' => home_url() ) );
+	elseif ( is_multisite() )
+		$wp_admin_bar->add_menu( array( 'title' => __( 'Dashboard' ), 'href' => get_dashboard_url( get_current_user_id() ) ) );
+	else
+		$wp_admin_bar->add_menu( array( 'title' => __( 'Dashboard' ), 'href' => admin_url() ) );
+}
+
 /**
  * Add the "My Sites/[Site Name]" menu and all submenus.
  *
@@ -160,15 +170,60 @@ function wp_admin_bar_shortlink_menu( $wp_admin_bar ) {
  * @since 3.1.0
  */
 function wp_admin_bar_edit_menu( $wp_admin_bar ) {
-	$current_object = get_queried_object();
+	global $post, $tag;
 
-	if ( empty($current_object) )
-		return;
+	if ( is_admin() ) {
+		$current_screen = get_current_screen();
 
-	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 || 'attachment' == $current_object->post_type ) ) {
-		$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 ) ) );
+		if ( 'post' == $current_screen->base
+			&& 'add' != $current_screen->action
+			&& ( $post_type_object = get_post_type_object( $post->post_type ) )
+			&& current_user_can( $post_type_object->cap->read_post, $post->ID )
+			&& ( $post_type_object->public ) )
+		{
+			$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 = 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 || 'attachment' == $current_object->post_type ) )
+		{
+			$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 )
+			) );
+		}
 	}
 }
 
diff --git a/wp-includes/class-wp-admin-bar.php b/wp-includes/class-wp-admin-bar.php
index 549d5ecf28..8a8c8fcede 100644
--- a/wp-includes/class-wp-admin-bar.php
+++ b/wp-includes/class-wp-admin-bar.php
@@ -180,6 +180,7 @@ class WP_Admin_Bar {
 
 	function add_menus() {
 		add_action( 'admin_bar_menu', 'wp_admin_bar_my_account_menu', 10 );
+		add_action( 'admin_bar_menu', 'wp_admin_bar_dashboard_view_site_menu', 15 );
 		add_action( 'admin_bar_menu', 'wp_admin_bar_my_sites_menu', 20 );
 		add_action( 'admin_bar_menu', 'wp_admin_bar_edit_menu', 30 );
 		add_action( 'admin_bar_menu', 'wp_admin_bar_shortlink_menu', 80 );
diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php
index 2874891fe7..9180b152b7 100644
--- a/wp-includes/taxonomy.php
+++ b/wp-includes/taxonomy.php
@@ -404,6 +404,7 @@ function get_taxonomy_labels( $tax ) {
 		'parent_item' => array( null, __( 'Parent Category' ) ),
 		'parent_item_colon' => array( null, __( 'Parent Category:' ) ),
 		'edit_item' => array( __( 'Edit Tag' ), __( 'Edit Category' ) ),
+		'view_item' => array( __( 'View Tag' ), __( 'View Category' ) ),
 		'update_item' => array( __( 'Update Tag' ), __( 'Update Category' ) ),
 		'add_new_item' => array( __( 'Add New Tag' ), __( 'Add New Category' ) ),
 		'new_item_name' => array( __( 'New Tag Name' ), __( 'New Category Name' ) ),