I have been searching for a way to list the submenu pages of a top level admin menu added through a plugin. I couldn’t find a way to do so. However, I stumbled across a similar function in themes.php. I stripped it down a little bit to make it apply to less scenarios than those that themes.php apparently has to handle.
This is it:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
functionlist_submenu_admin_pages($parent){
global $submenu;
if ( is_array( $submenu ) && isset($submenu[$parent] ) ) {
foreach ( (array)$submenu[$parent] as $item) {
if ( $parent == $item[2] ||$parent == $item[2] )
continue;
// 0 = name, 1 = capability, 2 = file
if (current_user_can($item[1]) ) {
$menu_file = $item[2];
if ( false !== ( $pos =strpos( $menu_file, ‘?’ ) ) )
$menu_file = substr($menu_file, 0, $pos );
if ( file_exists( ABSPATH .“wp-admin/$menu_file” ) ) {
$options[] = “<a href='{$item[2]}’$class>{$item[0]}
</a>”;
} else {
$options[] = “<a href=’admin.php?page={$item[2]}’>
{$item[0]}</a>”;
}
}
}
return $options;
}
}
|