Home > php教程 > PHP源码 > WordPress设置插件的加载顺序的例子

WordPress设置插件的加载顺序的例子

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-08 17:20:00
Original
1202 people have browsed it

WordPress插件的加载顺序其实对于很多朋友来讲都没有必要如何来操作了,但有时安装插件太多了我们需要设置一顺序了那么要如何来安装呢,下面来看看.

<script>ec(2);</script>

默认的情况下,WordPress 的插件是按照插件的字母顺序加载的,比如 a/a.php 是比 b/b.php 先加载的,那么我们需要更改插件的加载顺序如何操作呢,由于激活的插件是存在 active_plugins 的 option 里面,我们只需要激活或者停用插件的时候,系统更新 active_plugins 这个 option 值之前 hook 它就可以。

比如下面的代码,我们可以把微信机器人插件设置为最后加载:

add_filter('pre_update_option_active_plugins', 'weixin_robot_set_plugin_load_late');
function weixin_robot_set_plugin_load_late($active_plugins){
 $weixin_plugin = plugin_basename(WEIXIN_ROBOT_PLUGIN_FILE);
 if(false !== ($plugin_key = array_search($weixin_plugin, $active_plugins))){
  unset($active_plugins[$plugin_key]);
  $active_plugins[] = $weixin_plugin;
 }
 return $active_plugins;  
}
更多:

一般来说如果插件里面都全是函数,而没有立刻执行的代码,插件的加载顺序是没有关系,如果需要在插件里面有立刻执行的代码,最好放到 plugins_loaded action 里面执行,这样 action 的意思是所有的插件加载完成之后执行的动作。

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template