admin管理员组文章数量:1025822
I am creating a custom MU plugin to run on a multi-site network. I am working on a function that will dynamically include files containing additional action and filter hooks based on the active plugins for the current website being processed. The problem is, my function is not called when I visit a child site. Only the main site fires this event. How can I get it to execute the function regardless of the site I am on?
function my_plugin_autoload_plugin_hooks() {
$active_plugins = get_option('active_plugins');
// Include custom files from my plugin if they appear in the $active_plugin list.
}
add_action('plugins_loaded', 'my_plugin_autoload_plugin_hooks');
I am creating a custom MU plugin to run on a multi-site network. I am working on a function that will dynamically include files containing additional action and filter hooks based on the active plugins for the current website being processed. The problem is, my function is not called when I visit a child site. Only the main site fires this event. How can I get it to execute the function regardless of the site I am on?
function my_plugin_autoload_plugin_hooks() {
$active_plugins = get_option('active_plugins');
// Include custom files from my plugin if they appear in the $active_plugin list.
}
add_action('plugins_loaded', 'my_plugin_autoload_plugin_hooks');
Share
Improve this question
asked Oct 12, 2014 at 20:50
AdamAdam
3495 silver badges13 bronze badges
5
|
1 Answer
Reset to default 1With Multisite, you need to use add_site_option/get_site_option instead of add_option/get_option.
https://codex.wordpress/Function_Reference/get_site_option
I am creating a custom MU plugin to run on a multi-site network. I am working on a function that will dynamically include files containing additional action and filter hooks based on the active plugins for the current website being processed. The problem is, my function is not called when I visit a child site. Only the main site fires this event. How can I get it to execute the function regardless of the site I am on?
function my_plugin_autoload_plugin_hooks() {
$active_plugins = get_option('active_plugins');
// Include custom files from my plugin if they appear in the $active_plugin list.
}
add_action('plugins_loaded', 'my_plugin_autoload_plugin_hooks');
I am creating a custom MU plugin to run on a multi-site network. I am working on a function that will dynamically include files containing additional action and filter hooks based on the active plugins for the current website being processed. The problem is, my function is not called when I visit a child site. Only the main site fires this event. How can I get it to execute the function regardless of the site I am on?
function my_plugin_autoload_plugin_hooks() {
$active_plugins = get_option('active_plugins');
// Include custom files from my plugin if they appear in the $active_plugin list.
}
add_action('plugins_loaded', 'my_plugin_autoload_plugin_hooks');
Share
Improve this question
asked Oct 12, 2014 at 20:50
AdamAdam
3495 silver badges13 bronze badges
5
-
1
Where is the code above? What file? How is that piece of code loaded? What have you done to test the idea that the function doesn't fire? Have you tried a simple
wp_die('howdy');
, for example? – s_ha_dum Commented Oct 12, 2014 at 23:12 - Are you trying to load WordPress plugins without activation? – Austin Passy Commented Oct 13, 2014 at 18:47
- The code lives in the wp-content/mu-plugins folder. I was using xdebug and saw my breakpoints being hit in the function on my main site but not for a child site. – Adam Commented Oct 14, 2014 at 2:42
- I even tried just set a breakpoint at the very beginning of the plugin in the php file that sits directly in the mu-plugins folder and still didn't hit it on the child site. So it makes me think there is something wrong with mu-plugins running on a child site? – Adam Commented Oct 14, 2014 at 3:26
-
No, there isn't. I'm using that all the time with 40+ mu plugins in MS installations. Add an
exit( '<h1>HELLO!</h1>' );
to your plugin to see if it triggers. Else your setup (wp-config.php
and the directories) will have to be shown in the question - edit please - because then only those, in theory, should be able to affect your setup. – kaiser Commented Oct 15, 2014 at 11:48
1 Answer
Reset to default 1With Multisite, you need to use add_site_option/get_site_option instead of add_option/get_option.
https://codex.wordpress/Function_Reference/get_site_option
本文标签: multisiteAuto Load Plugin Hooks inside Must Use Plugin
版权声明:本文标题:multisite - Auto Load Plugin Hooks inside Must Use Plugin 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745639686a2160667.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
wp_die('howdy');
, for example? – s_ha_dum Commented Oct 12, 2014 at 23:12exit( '<h1>HELLO!</h1>' );
to your plugin to see if it triggers. Else your setup (wp-config.php
and the directories) will have to be shown in the question - edit please - because then only those, in theory, should be able to affect your setup. – kaiser Commented Oct 15, 2014 at 11:48