get_admin_page_parent()
Gets the parent page key of the admin panel, relative to the current page.
Sets the global admin variable global $parent_file which stores the name of the parent file responsible for displaying the current admin page. This name can be used in the keys of the global array $submenu: $submenu[ $parent ], where submenu items are added through the function add_submenu_page().
1 time — 0.000001 sec (speed of light) | 50000 times — 0.60 sec (very fast) | PHP 7.3.20, WP 5.5.3
No Hooks.
Returns
string. The key of the parent page in the admin panel. Examples of returned values:
profile.php users.php edit.php edit.php?post_type=page tools.php edit-tags.php?taxonomy=link_category
Usage
get_admin_page_parent( $parent );
- $parent(string)
- The slug of the parent admin menu item (or the file name for default menu items).
Default: ''
Examples
#1 Display the name of the parent file of the default menu item
Add a sub-menu item with add_submenu_page() to the Tools menu item.
add_action( 'admin_menu', 'mat_add_submenu_page' );
function mat_add_submenu_page() {
add_submenu_page(
'tools.php',
'Massive addition of terms',
'Massive addition of terms',
'manage_categories',
'mat-admin',
'mat_admin_page_content'
);
}
function mat_admin_page_content() {
echo get_admin_page_parent(); // output: tools.php
}
#2 Display the name of the parent file in CF7
Add a submenu to the Contact Form 7 main menu.
add_action( 'admin_menu', 'cf7_submodule_add_menu_page' );
function cf7_submodule_add_menu_page() {
add_submenu_page(
'wpcf7',
'Module for CF7',
'Module page for CF7',
'wpcf7_read_contact_forms',
'cf7-submodule-admin',
'cf7_submodule_admin_page_content'
);
}
function cf7_submodule_admin_page_content() {
echo get_admin_page_parent(); // output: wpcf7
}Notes
Global. String. $parent_file |
Global. Array. $menu |
Global. Array. $submenu |
Global. String. $pagenow The filename of the current screen. |
Global. String. $typenow The post type of the current screen. |
Global. String. $plugin_page |
Global. Array. $_wp_real_parent_file |
Global. Array. $_wp_menu_nopriv |
Global. Array. $_wp_submenu_nopriv |
Changelog
| Since 1.5.0 | Introduced. |