麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發(fā)設計 > 正文

淺析Wordpress的插件執(zhí)行流程

2019-11-17 04:26:46
字體:
來源:轉載
供稿:網友

1、首先,我現(xiàn)在pugins文件夾下寫一個自己的插件
復制php內容到剪貼板
PHP代碼:

<?php 
/*
Plugin Name: test
Plugin URI: [url=http://WordPRess.org/]http://wordpress.org/[/url]#
Description: 我測試用的
Author: lw(fantasy)
Version: 0.1
Author URI: [url=http://www.xxx.com/]http://www.xxx.com/[/url] 
*/ 
 
$test = "<div id='my_test'>這是我的第一個插件!</div>";

function output(){ 
    global $test;
    echo $test;
}

add_action('wp_footer','output');
?>


然后在后臺啟用。。

2、WP執(zhí)行是加載在”wp-settings.php”,而在此文件中,可以找到以下與插件相關的代碼片斷:
復制PHP內容到剪貼板
PHP代碼:
if ( get_option('active_plugins') ) {
$current_plugins = get_option('active_plugins');
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);
  }
}
}


我dump了一下$current_plugins,得到

Array
(
    [0] => Fanfou-Daily/Fanfou-Daily.php
    [1] => mulberrykit.php
    [2] => test.php
)

可以看到我寫的test.php插件已經被include進去了。。

3、在主題模板里的footer.php里面會執(zhí)行一個函數(shù)
<?php wp_footer(); ?>

而這個wp_footer里面又執(zhí)行

do_action('wp_footer');

而這個do_action就是執(zhí)行前面我們已經注冊了的【add_action('wp_footer','output'); 】output()函數(shù)。。。

這樣就輸出了"<div id='my_test'>這是我的第一個插件!</div>"了

最后貼一下do_action的源碼,大家體會一下吧
復制PHP內容到剪貼板
PHP代碼:
/**
* do_action() - Execute functions hooked on a specific action hook.
*
* This function invokes all functions attached to action hook <tt>$tag</tt>.
* It is possible to create new action hooks by simply calling this function,
* specifying the name of the new hook using the <tt>$tag</tt> parameter.
*
* 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($a);
// 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 $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 );
array_pop($wp_current_filter);
}


其中比較關鍵的就是call_user_func_array($the_['function'], array_slice($args, 0, (int) $the_['accepted_args']));這句了


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 一级免费| 精品在线观看一区二区 | 好吊色欧美一区二区三区四区 | 免费黄色一级网站 | 成人免费在线视频播放 | 影视免费观看 | 在线中文字幕观看 | 免费国产自久久久久三四区久久 | 欧美视频一级 | 国产精品久久久久久婷婷天堂 | 免费99热在线观看 | 91九色视频观看 | 国产毛片自拍 | 99精品国产一区二区三区 | 护士xxxx | 双性精h调教灌尿打屁股的文案 | 久久影院yy6080 | 狠狠干91 | 一级网站 | 一级免费黄视频 | 国产精品999在线观看 | 看黄在线 | 91精品国产九九九久久久亚洲 | 蜜桃av鲁一鲁一鲁一鲁 | 久久999精品久久久 国产噜噜噜噜久久久久久久久 | 成人情欲视频在线看免费 | 欧美精品一区二区三区久久久 | 免费国产之a视频 | 日本视频在线免费观看 | 精品国产乱码久久久久久久久 | 999精品国产 | 国产1区2| 爱福利视频网 | 国产毛片aaa一区二区三区视频 | 看片一区二区三区 | 亚洲一级簧片 | 欧洲精品色 | 一级一片免费看 | 日韩美香港a一级毛片免费 日韩激情 | 成人做爰s片免费看网站 | 国产一级桃视频播放 |