Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add additional checking to get_admin_page_parent() function #3017

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/wp-admin/includes/plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -1925,6 +1925,27 @@ function get_admin_page_parent( $parent_page = '' ) {
return $parent_file;
}

/**
* Check when $pagenow is edit.php or post-new.php for a
* custom post type and doesn't have a submenu
*
* edit.php?post_type=movies
* edit.php?post_type=movies
* post-new.php.php?post_type=movies
*/
if ( ! empty( $typenow ) && in_array( $pagenow, array( 'edit.php', 'post-new.php' ), true ) ) {
$post_type_menu = "edit.php?post_type=$typenow";
$post_type_submenu = "$pagenow?post_type=$typenow";

if (
! isset( $submenu[ $post_type_submenu ] ) &&
in_array( $post_type_menu, array_column( $menu, 2 ), true )
) {
$parent_file = $post_type_menu;
return $parent_file;
}
}

foreach ( array_keys( (array) $submenu ) as $parent_page ) {
foreach ( $submenu[ $parent_page ] as $submenu_array ) {
if ( isset( $_wp_real_parent_file[ $parent_page ] ) ) {
Expand Down