How to access $menu variable in custom .PHP file that loads wp-load.php?
I have a file custom.php
inside the WP root folder. My goal is to access the GLOBAL $menu
variable that stores the admin menu items. In order to do that, I try loading the WordPress environment.
?php require $_SERVER['DOCUMENT_ROOT'].'/wp-load.php'; ?
After loading, I checked and made sure that the WordPress environment has been loaded.
if (defined('ABSPATH')) echo "WP Environment loaded."
Even when the wp-load.php is loaded, I am unable to access the global variable $menu which I can under a plugin file.
Is there any other file that needs to be loaded? Does the code after wp-load.php get executed after all the plugins were loaded?
Here is the whole code inside the file.
ROOT FOLDER
|__ customer (folder)
| |_______test.php
|__ wp-admin
|__ wp-content
|__ ...
Here is what inside test.php
?php
require $_SERVER['DOCUMENT_ROOT'].'/wp-load.php';
global $menu;
if (defined('ABSPATH')) {
echo "WP Environment loaded.br";
echo "Admin menu returns " .json_encode( $menu );
}
?
And this is the output result:
WP Environment loaded.brAdmin menu returns null
Topic wp-load.php admin-menu Wordpress
Category Web