Example of loading sequence for WordPress plug-ins-PHP source code

Source: Internet
Author: User
The loading sequence of WordPress plug-ins is not necessary for many friends, but sometimes there are too many plug-ins to be installed. We need to set the sequence. How can we install them, let's take a look. the loading sequence of WordPress plug-ins is not necessary for many friends, but sometimes there are too many plug-ins to be installed. We need to set the sequence. How can we install them, let's take a look.

Script ec (2); script

By default, WordPress plug-ins are loaded alphabetically by plug-ins, such as a/. php is better than B/B. php loads the plug-in first, so how do we change the loading sequence of the plug-in? Because the activated plug-in exists in the option of active_plugins, we only need to activate or disable the plug-in, the system can hook active_plugins before updating the option value.

For example, the following code sets the robot plug-in as the final load:

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;
}
More:

Generally, if the plug-in contains all functions but no code to be executed immediately, the loading sequence of the plug-in is irrelevant. If you need to have the code to be executed immediately in the plug-in, it is best to put it in plugins_loaded action for execution. This action means the actions executed after all the plug-ins are loaded.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.