php global变量初始化,wordpress全局变量$wpdb初始化并声明为全局变量的方法

首先从wordpress程序index.php入手:

复制代码代码如下:

define(\’WP_USE_THEMES\’, true);

/** Loads the WordPress Environment and Template */

require( dirname( __FILE__ ) . \’/wp-blog-header.php\’ );

index.php加载了wp-blog-header.php文件,再打开看看:

复制代码代码如下:

if ( !isset($wp_did_header) ) {

$wp_did_header = true;

require_once( dirname(__FILE__) . \’/wp-load.php\’ );

wp();

require_once( ABSPATH . WPINC . \’/template-loader.php\’ );

}

再打开wp-load.php:

复制代码代码如下:

if ( file_exists( ABSPATH . \’wp-config.php\’) ) {

/** The config file resides in ABSPATH */

require_once( ABSPATH . \’wp-config.php\’ );

} elseif ( file_exists( dirname(ABSPATH) . \’/wp-config.php\’ ) && ! file_exists( dirname(ABSPATH) . \’/wp-settings.php\’ ) ) {

/** The config file resides one level above ABSPATH but is not part of another install */

require_once( dirname(ABSPATH) . \’/wp-config.php\’ );

} else {

……

}

它加载了配置文件config.php,打开config.php看看:

复制代码代码如下:

/* 好了!请不要再继续编辑。请保存本文件。使用愉快! */

/** WordPress目录的绝对路径。 */

if ( !defined(\’ABSPATH\’) )

define(\’ABSPATH\’, dirname(__FILE__) . \’/\’);

/** 设置WordPress变量和包含文件。 */

require_once(ABSPATH . \’wp-settings.php\’);

找到最下面几行,它加载了wp-settings.php文件,打开看看:

复制代码代码如下:

define( \’WPINC\’, \’wp-includes\’ );

// Include files required for initialization.

require( ABSPATH . WPINC . \’/load.php\’ );

require( ABSPATH . WPINC . \’/default-constants.ph...

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值