I don’t think it’s possible without accessing a global. This seems to work for all pages types, by using the global $_parent_pages
with the function get_plugin_page_hookname
:
function nackle_get_screen_id( $slug ){
global $_parent_pages;
$parent = array_key_exists( $slug, $_parent_pages ) ? $_parent_pages[$slug] : '';
return get_plugin_page_hookname( $slug, $parent );
}
Usage example:
echo nackle_get_screen_id( 'my-custom-page-key' );
Edit- This can be used on or after admin_init
, which is when the menu is parsed and $_parent_pages
is populated.