get_plugin_page_hookname() WordPress Function

The get_plugin_page_hookname() function is used to get the hook name for a plugin page. This is useful for plugin authors who need to add custom code to their plugin pages.

get_plugin_page_hookname( string $plugin_page, string $parent_page ) #

Gets the hook name for the administrative page of a plugin.


Parameters

$plugin_page

(string)(Required)The slug name of the plugin page.

$parent_page

(string)(Required)The slug name for the parent menu (or the file name of a standard WordPress admin page).


Top ↑

Return

(string) Hook name for the plugin page.


Top ↑

Source

File: wp-admin/includes/plugin.php

function get_plugin_page_hookname( $plugin_page, $parent_page ) {
	global $admin_page_hooks;

	$parent = get_admin_page_parent( $parent_page );

	$page_type = 'admin';
	if ( empty( $parent_page ) || 'admin.php' === $parent_page || isset( $admin_page_hooks[ $plugin_page ] ) ) {
		if ( isset( $admin_page_hooks[ $plugin_page ] ) ) {
			$page_type = 'toplevel';
		} elseif ( isset( $admin_page_hooks[ $parent ] ) ) {
			$page_type = $admin_page_hooks[ $parent ];
		}
	} elseif ( isset( $admin_page_hooks[ $parent ] ) ) {
		$page_type = $admin_page_hooks[ $parent ];
	}

	$plugin_name = preg_replace( '!\.php!', '', $plugin_page );

	return $page_type . '_page_' . $plugin_name;
}


Top ↑

Changelog

Changelog
VersionDescription
1.5.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.