wordpress全局变量$wpdb在哪里进行初始化申明

wordpress操作数据库用一个全局变量$wpdb来进行各种操作,应用的时分先在函数申明global $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.php' );
require( ABSPATH . WPINC . '/version.php' );

它加载了load.php文件,关上load.php文件其中有个函数:
 
function require_wp_db() {
global $wpdb;
require_once( ABSPATH . WPINC . '/wp-db.php' );
if ( file_exists( WP_CONTENT_DIR . '/db.php' ) )
require_once( WP_CONTENT_DIR . '/db.php' );
if ( isset( $wpdb ) )
return;
$wpdb = new wpdb( DB_USER, DB_PASSWORD, DB_NAME, DB_HOST );
}

并且在该文件(wp-settings.php)上面调用了require_wp_db()办法:
 
// Include the wpdb class and, if present, a db.php database drop-in.
require_wp_db();

于是找到了,通过层层加载文件和调用,在这里进行了$wpdb这个变量的全局定义。

以上就是安达网络工作室关于《wordpress全局变量$wpdb在哪里进行初始化声明》的一些看法。更多内容请查看本栏目更多内容!

本文相关话题: wordpress 全局变量 wpdb
版权声明:本文为 安达网络工作室 转载文章,如有侵权请联系我们及时删除。
相关文章
wordpress 网站转移效劳器操作的两种办法

第一种办法:我的这个博客不断都在网上运转,明天想把它在本地架设一个,包括数据库都和网上的如出一辙。详...

以WordPress为例解说jQuery丑化页面Title的办法

这里选取的例子,便是 WordPress 中比拟有名的丑化超链接Title成果,普通的 title 成果是把鼠标放到 a 元素...

如何制造WordPress主题言语包(汉化主题)

通过这次yHtml5主题的制造,我学会了怎样给主题制造言语包,就是普通的汉化主题啦。废话不多说,说步骤。 首...

WordPress中制造导航菜单的PHP外围办法解说

WordPress 3.0 引入导航菜单性能, 让页面的导航和链接的治理变得简略易用. WP 向用户提供了菜单治理页面和多...

为Wordpress博客增加MP3播放器

首先到Flash MP3 Player 的主页上下载该顺序。解紧缩之后,将 mp3player.swf 和 ufo.js 两个文件放到效劳器...

详解WordPress中分类函数wp_list_categories的应用

wp_list_categories 函数是 WordPress 中用来列举零碎中分类的函数,该函数领有许多管制输入的参数,明天忽...

需求提交

客服服务