Welcome 微信登录

首页 / 网页编程 / PHP / 浅析Wordpress的插件执行流程

浅析Wordpress的插件执行流程2010-12-261、首先,我现在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执行是加载在”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里面会执行一个函数

<?php wp_footer(); ?>

而这个wp_footer里面又执行

do_action("wp_footer");