get_plugin_page_hookname

The timeline below displays how wordpress function get_plugin_page_hookname has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 5.5

/**
 * Gets the hook name for the administrative page of a plugin.
 *
 * @since 1.5.0
 *
 * @global array $admin_page_hooks
 *
 * @param string $plugin_page The slug name of the plugin page.
 * @param string $parent_page The slug name for the parent menu (or the file name of a standard
 *                            WordPress admin page).
 * @return string Hook name for the plugin page.
 */
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;
}

WordPress Version: 5.4

/**
 * Gets the hook name for the administrative page of a plugin.
 *
 * @since 1.5.0
 *
 * @global array $admin_page_hooks
 *
 * @param string $plugin_page The slug name of the plugin page.
 * @param string $parent_page The slug name for the parent menu (or the file name of a standard
 *                            WordPress admin page).
 * @return string Hook name for the plugin page.
 */
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;
}

WordPress Version: 5.2

/**
 * @global array $admin_page_hooks
 *
 * @param string $plugin_page The slug name of the plugin page.
 * @param string $parent_page The slug name for the parent menu (or the file name of a standard
 *                            WordPress admin page).
 * @return string Hook name for the plugin page.
 */
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;
}

WordPress Version: 5.1

/**
 * @global array $admin_page_hooks
 * @param string $plugin_page
 * @param string $parent_page
 */
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;
}

WordPress Version: 4.3

/**
 *
 * @global array $admin_page_hooks
 * @param string $plugin_page
 * @param string $parent_page
 */
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;
}

WordPress Version: 4.2

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;
}

WordPress Version: 3.7

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';
        } else if (isset($admin_page_hooks[$parent])) {
            $page_type = $admin_page_hooks[$parent];
        }
    } else if (isset($admin_page_hooks[$parent])) {
        $page_type = $admin_page_hooks[$parent];
    }
    $plugin_name = preg_replace('!\.php!', '', $plugin_page);
    return $page_type . '_page_' . $plugin_name;
}