diff --git a/src/wp-includes/admin-bar.php b/src/wp-includes/admin-bar.php index 2f7c02a497..4c4765d88a 100644 --- a/src/wp-includes/admin-bar.php +++ b/src/wp-includes/admin-bar.php @@ -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 ) ) diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index ced823c320..c02108eba7 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -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.') ), diff --git a/tests/phpunit/tests/adminbar.php b/tests/phpunit/tests/adminbar.php index 12a767d9f6..32507e3ce3 100644 --- a/tests/phpunit/tests/adminbar.php +++ b/tests/phpunit/tests/adminbar.php @@ -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 ); + } }