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
This commit is contained in:
nacin 2011-06-08 16:49:27 +00:00
parent 029a8d1bef
commit 71c2782b1c
4 changed files with 69 additions and 11 deletions

View File

@ -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 ) 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['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( 'tag_row_actions', $actions, $tag );
$actions = apply_filters( "{$taxonomy}_row_actions", $actions, $tag ); $actions = apply_filters( "{$taxonomy}_row_actions", $actions, $tag );

View File

@ -89,14 +89,24 @@ function wp_admin_bar_my_account_menu( $wp_admin_bar ) {
/* Add the "My Account" sub menus */ /* 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 ) ) ); $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() ) ); $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. * 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 * @since 3.1.0
*/ */
function wp_admin_bar_edit_menu( $wp_admin_bar ) { function wp_admin_bar_edit_menu( $wp_admin_bar ) {
$current_object = get_queried_object(); global $post, $tag;
if ( empty($current_object) ) if ( is_admin() ) {
return; $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 ) ) { if ( 'post' == $current_screen->base
$wp_admin_bar->add_menu( array( 'id' => 'edit', 'title' => $post_type_object->labels->edit_item, 'href' => get_edit_post_link( $current_object->ID ) ) ); && 'add' != $current_screen->action
} elseif ( ! empty( $current_object->taxonomy ) && ( $tax = get_taxonomy( $current_object->taxonomy ) ) && current_user_can( $tax->cap->edit_terms ) && $tax->show_ui ) { && ( $post_type_object = get_post_type_object( $post->post_type ) )
$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 ) ) ); && 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 )
) );
}
} }
} }

View File

@ -180,6 +180,7 @@ class WP_Admin_Bar {
function add_menus() { function add_menus() {
add_action( 'admin_bar_menu', 'wp_admin_bar_my_account_menu', 10 ); 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_my_sites_menu', 20 );
add_action( 'admin_bar_menu', 'wp_admin_bar_edit_menu', 30 ); add_action( 'admin_bar_menu', 'wp_admin_bar_edit_menu', 30 );
add_action( 'admin_bar_menu', 'wp_admin_bar_shortlink_menu', 80 ); add_action( 'admin_bar_menu', 'wp_admin_bar_shortlink_menu', 80 );

View File

@ -404,6 +404,7 @@ function get_taxonomy_labels( $tax ) {
'parent_item' => array( null, __( 'Parent Category' ) ), 'parent_item' => array( null, __( 'Parent Category' ) ),
'parent_item_colon' => array( null, __( 'Parent Category:' ) ), 'parent_item_colon' => array( null, __( 'Parent Category:' ) ),
'edit_item' => array( __( 'Edit Tag' ), __( 'Edit Category' ) ), 'edit_item' => array( __( 'Edit Tag' ), __( 'Edit Category' ) ),
'view_item' => array( __( 'View Tag' ), __( 'View Category' ) ),
'update_item' => array( __( 'Update Tag' ), __( 'Update Category' ) ), 'update_item' => array( __( 'Update Tag' ), __( 'Update Category' ) ),
'add_new_item' => array( __( 'Add New Tag' ), __( 'Add New Category' ) ), 'add_new_item' => array( __( 'Add New Tag' ), __( 'Add New Category' ) ),
'new_item_name' => array( __( 'New Tag Name' ), __( 'New Category Name' ) ), 'new_item_name' => array( __( 'New Tag Name' ), __( 'New Category Name' ) ),