Analysis of the Wordpress plug-in execution process, read and analyze the Wordpress plug-in execution process, 1. first, I write my own plug-in under the pugins folder to copy the PHP content to the clipboard PHP code :? Php/* PluginName: testPluginURI: [url = http://wordpress.org/#http://wordpr
1. first, I will write my own plug-in the pugins folder.
Copy the PHP content to the clipboard.
PHP code:
/*
Plugin Name: test
Plugin URI: [url = http://wordpress.org/#http://wordpress.org/#/url##
Description: used in the test.
Author: lw (fantasy)
Version: 0.1
Author URI: [url = http://www.xxx.com/?http://www.xxx.com/#/url]
*/
$ Test = "this is my first plug-in! ";
Function output (){
Global $ test;
Echo $ test;
}
Add_action ('WP _ footer ', 'output ');
?>
And then enable it in the background ..
2. WP execution is loaded in the wp-settings.php, and in this file, you can find the following plug-in-related code snippets:
Copy the PHP content to the clipboard.
PHP code:
If (get_option ('active _ ins ')){
$ Current_plugins = get_option ('active _ ins ins ');
Dump ($ current_plugins );
If (is_array ($ current_plugins )){
Foreach ($ current_plugins as $ plugin ){
If (''! = $ Plugin & 0 = validate_file ($ plugin) & file_exists (WP_PLUGIN_DIR. '/'. $ plugin ))
Include_once (WP_PLUGIN_DIR. '/'. $ plugin );
}
}
}
I dumped $ current_plugins and got
Array
(
[0] => Fanfou-Daily/Fanfou-Daily.php
[1] => mulberrykit. php
[2] => test. php
)
The test. php plug-in I wrote has been included ..
3. a function is executed in footer. php of the topic template.
And this wp_footer is executed again.
Do_action ('WP _ footer ');
And this do_action is to execute the previously registered [add_action ('WP _ footer ', 'output');] output () function...
This outputs "this is my first plug-in! "
Finally, paste the do_action source code.
Copy the PHP content to the clipboard.
PHP code:
/**
* Do_action ()-Execute functions hooked on a specific action hook.
*
* This function invokes all functions attached to action hook$ Tag.
* It is possible to create new action hooks by simply calling this function,
* Specifying the name of the new hook using$ TagParameter.
*
* You can pass extra arguments to the hooks, much like you can with apply_filters ().
*
* @ See apply_filters () This function works similar with the exception that nothing is
* Returned and only the functions or methods are called.
*
* @ Package WordPress
* @ Subpackage Plugin
* @ Since 1.2
* @ Global array $ wp_filter Stores all of the filters
* @ Global array $ wp_actions Increments the amount of times action was triggered.
*
* @ Param string $ tag The name of the action to be executed.
* @ Param mixed $ arg,... Optional additional arguments which are passed on to the functions hooked to the action.
* @ Return null Will return null if $ tag does not exist in $ wp_filter array
*/
Function do_action ($ tag, $ arg = ''){
Global $ wp_filter, $ wp_actions, $ merged_filters, $ wp_current_filter;
If (is_array ($ wp_actions ))
$ Wp_actions [] = $ tag;
Else
$ Wp_actions = array ($ tag );
$ Wp_current_filter [] = $ tag;
// Do 'all' actions first
If (isset ($ wp_filter ['all']) {
$ All_args = func_get_args ();
_ Wp_call_all_hook ($ all_args );
}
If (! Isset ($ wp_filter [$ tag]) {
Array_pop ($ wp_current_filter );
Return;
}
$ Args = array ();
If (is_array ($ arg) & 1 = count ($ arg) & is_object ($ arg [0]) // array (& $ this)
$ Args [] = & $ arg [0];
Else
$ Args [] = $ arg;
For ($ a = 2; $ a <func_num_args (); $ a ++)
$ Args [] = func_get_arg ($ );
// Sort
If (! Isset ($ merged_filters [$ tag]) {
Ksort ($ wp_filter [$ tag]);
$ Merged_filters [$ tag] = true;
}
Reset ($ wp_filter [$ tag]);
Do {
Foreach (array) current ($ wp_filter [$ tag]) as $ _)
If (! Is_null ($ the _ ['function'])
Call_user_func_array ($ the _ ['function'], array_slice ($ args, 0, (int) $ the _ ['accepted _ args ']);
} While (next ($ wp_filter [$ tag])! = False );
Array_pop ($ wp_current_filter );
}
Among them, the key is call_user_func_array ($ the _ ['function'], array_slice ($ args, 0, (int) $ the _ ['accepted _ args ']); this sentence