namespace not working correctly | WordPress.org

[ad_1]

In the main plugin file, the callback function of the hook has to be like the below if I’m using namespace:


namespace test;

add_action('admin_menu', __NAMESPACE__ . '\function_name');

But why if I include a file called load.php on the main plugin file, and it works like normal without mentioning the __NAMESPACE__?
So it looks like this on the main plugin file now:


require_once __DIR__ . '/includes/load.php';

The load.php looks like the below and it works:


namespace test;

add_action('admin_menu', 'function_name')

But why if I use the exact same code from load.php on the main plugin file and it won’t work until I make it like:


namespace test;

add_action('admin_menu', __NAMESPACE__ . '\function_name');

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer