The function below is intended to return a list of the WordPress submenu pages.
function get_admin_menus() {
global $submenu, $menu, $pagenow;
if ( current_user_can('manage_options') ) {
if( $pagenow == 'index.php' ) {
foreach ( $submenu as $index => $menu_item ) {
foreach ( $menu_item as $value) {
$submenu_page = $value[2];
// return $submenu_page;
echo $submenu_page;
}
}
}
}
}
Adding the action add_action( 'admin_notices', 'get_admin_menus' );
displays a list of the submenu items. This only works with echo
.
I would like to return the values into another function however when using return $submenu_page
with echo get_admin_menus()
does not appear to work.
For example:
function test () {
echo get_admin_menus();
}
What am I missing or doing wrong?