I am wondering if this is possible or if there is another, better way, of doing things. Google-foo didn't help.
So, I have two plugins, aa-frontend and aa-site. I need to define a constant or variable in aa-site/plugin.php and use it in aa-frontend/folder/somefile.php.
Tried with:
function site_wp_features(){
define('AA_PLUGIN_GUTENBERG', false);
}
add_action('plugins_loaded', 'site_wp_features', 0)
But I get:
Warning: Use of undefined constant AA_PLUGIN_GUTENBERG
Any ideas?
I am wondering if this is possible or if there is another, better way, of doing things. Google-foo didn't help.
So, I have two plugins, aa-frontend and aa-site. I need to define a constant or variable in aa-site/plugin.php and use it in aa-frontend/folder/somefile.php.
Tried with:
function site_wp_features(){
define('AA_PLUGIN_GUTENBERG', false);
}
add_action('plugins_loaded', 'site_wp_features', 0)
But I get:
Warning: Use of undefined constant AA_PLUGIN_GUTENBERG
Any ideas?
instead of using a constant, define the variable as an option stored in the wp_options table so that it can be accessed from any plugin.
To ensure that the constant is defined before it is accessed, you can use the init
action hook instead of plugins_loaded
, as init
is fired after wp has finished loading but before any headers are sent.
function site_define_constant() {
define('AA_PLUGIN_GUTENBERG', false);
}
add_action('init', 'site_define_constant');
AA_PLUGIN_GUTENBERG
should be defined by the time wp reaches the init hook, and you should no longer encounter the Use of undefined constant
warning.
Then, in aa-frontend/folder/somefile.php
, you can access the constant like below code
if (defined('AA_PLUGIN_GUTENBERG') && AA_PLUGIN_GUTENBERG) {
// Constant is defined and set to true
} else {
// Constant is either not defined or set to false
}