Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/Admin/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,24 @@ public function addAdminBarArchiveLink(WP_Admin_Bar $adminBar): void
*/
public function addPostTypeSubmenus(): void
{
$pageId = get_option('page_for_posts');
$postTypeObject = get_post_type_object('post');
if ($postTypeObject && $pageId) {
$postType = 'post';
$editPostLink = get_edit_post_link($pageId);
if ($editPostLink) {
$archivesLabel = \is_string($postTypeObject->labels->archives) ? $postTypeObject->labels->archives : $postType;

add_submenu_page(
'edit.php',
$archivesLabel,
$archivesLabel,
'edit_pages',
$editPostLink
);
}
}

foreach ($this->api->getPageIds() as $postType => $pageId) {
$postTypeObject = get_post_type_object($postType);
if (!$postTypeObject) {
Expand Down
18 changes: 16 additions & 2 deletions tests/Integration/AdminScreenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,27 @@ public function testRenderPageDropdownOutputsSelectElement(): void
$this->assertStringContainsString('_use_slug', $output);
}

public function testAddPostTypeSubmenusAddsSubmenus(): void
public function testAddPostSubmenusAddsSubmenus(): void
{
$postsPageId = static::factory()->post->create(['post_type' => 'page', 'post_status' => 'publish']);
update_option('page_for_posts', $postsPageId);

$this->acting_as('administrator');

$this->admin->addPostTypeSubmenus();

// Check submenus was added for posts
$postMenuKey = 'edit.php';
$this->assertArrayHasKey($postMenuKey, $GLOBALS['submenu'] ?? []);
}

public function testAddCustomPostTypeSubmenusAddsSubmenus(): void
{
$this->acting_as('administrator');

$this->admin->addPostTypeSubmenus();

// Check submenus were added for at least one post type
// Check submenus were added for at least one custom post type
$bookMenuKey = 'edit.php?post_type=' . self::BOOK_POST_TYPE;
$this->assertArrayHasKey($bookMenuKey, $GLOBALS['submenu'] ?? []);
}
Expand Down