Toolbar: Add a 'View Posts' link to the toolbar when on the post listing screen.

This adds a new link to visit the post type archive if the post type supports it. Also introduces a new `view_items` label to `get_post_type_labels()`.

Props paulwilde, akibjorklund, swissspidy.
Fixes #34113.

git-svn-id: https://develop.svn.wordpress.org/trunk@38634 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Pascal Birchler 2016-09-20 20:01:55 +00:00
parent debaea8a7c
commit acb43ecc0b
3 changed files with 41 additions and 0 deletions

View File

@ -577,6 +577,17 @@ function wp_admin_bar_edit_menu( $wp_admin_bar ) {
'href' => get_permalink( $post->ID )
) );
}
} elseif ( 'edit' == $current_screen->base
&& ( $post_type_object = get_post_type_object( $current_screen->post_type ) )
&& ( $post_type_object->public )
&& ( $post_type_object->show_in_admin_bar )
&& ( get_post_type_archive_link( $post_type_object->name ) ) )
{
$wp_admin_bar->add_node( array(
'id' => 'archive',
'title' => $post_type_object->labels->view_items,
'href' => get_post_type_archive_link( $current_screen->post_type )
) );
} elseif ( 'term' == $current_screen->base
&& isset( $tag ) && is_object( $tag ) && ! is_wp_error( $tag )
&& ( $tax = get_taxonomy( $tag->taxonomy ) )

View File

@ -1234,6 +1234,7 @@ function _post_type_meta_capabilities( $capabilities = null ) {
* - `edit_item` - Label for editing a singular item. Default is 'Edit Post' / 'Edit Page'.
* - `new_item` - Label for the new item page title. Default is 'New Post' / 'New Page'.
* - `view_item` - Label for viewing a singular item. Default is 'View Post' / 'View Page'.
* - `view_items` - Label for viewing post type archives. Default is 'View Posts' / 'View Pages'.
* - `search_items` - Label for searching plural items. Default is 'Search Posts' / 'Search Pages'.
* - `not_found` - Label used when no items are found. Default is 'No posts found' / 'No pages found'.
* - `not_found_in_trash` - Label used when no items are in the trash. Default is 'No posts found in Trash' /
@ -1267,6 +1268,7 @@ function _post_type_meta_capabilities( $capabilities = null ) {
* @since 4.4.0 Added the `insert_into_item`, `uploaded_to_this_item`, `filter_items_list`,
* `items_list_navigation`, and `items_list` labels.
* @since 4.6.0 Converted the `$post_type` parameter to accept a WP_Post_Type object.
* @since 4.7.0 Added the `view_items` label.
*
* @access private
*
@ -1282,6 +1284,7 @@ function get_post_type_labels( $post_type_object ) {
'edit_item' => array( __('Edit Post'), __('Edit Page') ),
'new_item' => array( __('New Post'), __('New Page') ),
'view_item' => array( __('View Post'), __('View Page') ),
'view_items' => array( __('View Posts'), __('View Pages') ),
'search_items' => array( __('Search Posts'), __('Search Pages') ),
'not_found' => array( __('No posts found.'), __('No pages found.') ),
'not_found_in_trash' => array( __('No posts found in Trash.'), __('No pages found in Trash.') ),

View File

@ -380,4 +380,31 @@ class Tests_AdminBar extends WP_UnitTestCase {
$this->assertNull( $node_edit );
}
/**
* @ticket 34113
*/
public function test_admin_bar_contains_view_archive_link() {
set_current_screen( 'edit-post' );
$wp_admin_bar = $this->get_standard_admin_bar();
$node = $wp_admin_bar->get_node( 'archive' );
set_current_screen( 'front' );
$this->assertNotNull( $node );
}
/**
* @ticket 34113
*/
public function test_admin_bar_has_no_archives_link_for_post_types_without_archive() {
set_current_screen( 'edit-page' );
$wp_admin_bar = $this->get_standard_admin_bar();
$node = $wp_admin_bar->get_node( 'archive' );
set_current_screen( 'front' );
$this->assertNull( $node );
}
}