wordpress source code analysis(2)

In the previous chapter, we know wp-settings.php is a complex file. This file loads almost everything like plugins and active theme. We will look into it further.

After including plugin functions such as add_filter, add_actions from wp-includes/plugin.php, it loads wp-includes/default-filters.php to add a lot of predefined filters and actions. After that, it can stop loading other stuff if we just want the basics. Otherwise, it continues to load a bunch of other files, load must use plugins. Then do the first action do_action( 'muplugins_loaded' ).

The core part of do_action function is :

do {
  foreach ( (array) current($wp_filter[$tag]) as $the_ )
  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 );

 

The actions(functions) asscociated with the tag are stored in the array of array $wp_filter[$tag]. The loop calls all those functions with the parameter args.

Note that $wp_filter[$tag] is a two-dimension array. The first dimension is proirity and the second dimension is function name. The outer loop iterates over the proirities and the inner loop iterates over the functions.

If you like my content, please consider buying me a coffee. Buy me a coffeeBuy me a coffee Thank you for your support!

Leave a Reply