wppaste
WordPress

get_admin_page_parent( string $parent_page = '' ): string

Since
1.5.0
Source
wp-admin/includes/plugin.php:1969
Gets the parent file of the current admin page.

Compatibility

WordPress
since 1.5.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$parent_pagestringoptional
The slug name for the parent menu (or the file name of a standard WordPress admin page). Default empty string.Default: ''

Return value

string
The parent file of the current admin page.

Performance profile

How much work a call to get_admin_page_parent() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Light

Touches nothing outside its own arguments.

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
17–68

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 110.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
3

3 places in core call this, so the cost is paid more often than your own code shows.

What one call costs · 2 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost get_admin_page_parent() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
always17–35none
!isset($plugin_page)25–68array_keys()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev11017–6828
8.511017–6828
8.411017–68283 fewer instructions than PHP 8.3
8.311317–7128
8.211317–7128
8.111317–7128
7.411317–7128

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Uses · 1

  • str_contains()Polyfill for `str_contains()` function added in PHP 8.0.

Used by · 3

Source code

function get_admin_page_parent( $parent_page = '' ) {	global $parent_file, $menu, $submenu, $pagenow, $typenow,		$plugin_page, $_wp_real_parent_file, $_wp_menu_nopriv, $_wp_submenu_nopriv; 	if ( ! empty( $parent_page ) && 'admin.php' !== $parent_page ) {		if ( isset( $_wp_real_parent_file[ $parent_page ] ) ) {			$parent_page = $_wp_real_parent_file[ $parent_page ];		} 		return $parent_page;	} 	if ( 'admin.php' === $pagenow && isset( $plugin_page ) ) {		foreach ( (array) $menu as $parent_menu ) {			if ( $parent_menu[2] === $plugin_page ) {				$parent_file = $plugin_page; 				if ( isset( $_wp_real_parent_file[ $parent_file ] ) ) {					$parent_file = $_wp_real_parent_file[ $parent_file ];				} 				return $parent_file;			}		}		if ( isset( $_wp_menu_nopriv[ $plugin_page ] ) ) {			$parent_file = $plugin_page; 			if ( isset( $_wp_real_parent_file[ $parent_file ] ) ) {					$parent_file = $_wp_real_parent_file[ $parent_file ];			} 			return $parent_file;		}	} 	if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[ $pagenow ][ $plugin_page ] ) ) {		$parent_file = $pagenow; 		if ( isset( $_wp_real_parent_file[ $parent_file ] ) ) {			$parent_file = $_wp_real_parent_file[ $parent_file ];		} 		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 ] ) ) {				$parent_page = $_wp_real_parent_file[ $parent_page ];			} 			if ( ! empty( $typenow ) && "$pagenow?post_type=$typenow" === $submenu_array[2] ) {				$parent_file = $parent_page;				return $parent_page;			} elseif ( empty( $typenow ) && $pagenow === $submenu_array[2]				&& ( empty( $parent_file ) || ! str_contains( $parent_file, '?' ) )			) {				$parent_file = $parent_page;				return $parent_page;			} elseif ( isset( $plugin_page ) && $plugin_page === $submenu_array[2] ) {				$parent_file = $parent_page;				return $parent_page;			}		}	} 	if ( empty( $parent_file ) ) {		$parent_file = '';	}	return '';}

Changelog

Introduced in 1.5.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 6.9.7 tag, from src/wp-admin/includes/plugin.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.