Fix submenus for post types. Props TobiasBg. see #12453

git-svn-id: http://svn.automattic.com/wordpress/trunk@13579 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan
2010-03-04 00:15:55 +00:00
parent 779a3e76dd
commit aa47e83dee
5 changed files with 52 additions and 23 deletions

View File

@@ -817,6 +817,7 @@ function add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $func
$admin_page_hooks[$menu_slug] = sanitize_title( $menu_title );
$hookname = get_plugin_page_hookname( $menu_slug, '' );
if (!empty ( $function ) && !empty ( $hookname ) && current_user_can( $capability ) )
add_action( $hookname, $function );
@@ -1167,6 +1168,7 @@ function get_admin_page_parent( $parent = '' ) {
global $menu;
global $submenu;
global $pagenow;
global $typenow;
global $plugin_page;
global $_wp_real_parent_file;
global $_wp_menu_nopriv;
@@ -1215,7 +1217,10 @@ function get_admin_page_parent( $parent = '' ) {
foreach ( $submenu[$parent] as $submenu_array ) {
if ( isset( $_wp_real_parent_file[$parent] ) )
$parent = $_wp_real_parent_file[$parent];
if ( $submenu_array[2] == $pagenow && ( empty($parent_file) || false === strpos($parent_file, '?') ) ) {
if ( !empty($typenow) && ($submenu_array[2] == "$pagenow?post_type=$typenow") ) {
$parent_file = $parent;
return $parent;
} elseif ( $submenu_array[2] == $pagenow && empty($typenow) && ( empty($parent_file) || false === strpos($parent_file, '?') ) ) {
$parent_file = $parent;
return $parent;
} else
@@ -1326,6 +1331,7 @@ function get_plugin_page_hookname( $plugin_page, $parent_page ) {
$page_type = $admin_page_hooks[$parent];
}
$plugin_name = preg_replace( '!\.php!', '', $plugin_page );
return $page_type.'_page_'.$plugin_name;
@@ -1350,6 +1356,7 @@ function user_can_access_admin_page() {
return false;
$hookname = get_plugin_page_hookname($plugin_page, $parent);
if ( !isset($_registered_pages[$hookname]) )
return false;
}