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.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 2.7 开端退出了“置顶文章(Sticky Posts)”。置顶文章的作用是心愿长工夫惹起读者留...

WordPress 3.5 与 wpdb::prepare() 报错处理方法

WordPress 3.5 正式公布, 这个版本包括大量更新. 启用了最新的呼应式规划默许主题 Twenty Twelve; 改版了 A...

wordpress暴门路 影响一切版本

缺点文件/{Path}/wp-includes/registration-functions.php 要害代码: &mdash;-> <?php /** * Deprecated. N...

制止wordpress主动将半角转换为全角 制止全角和半角的转换

找到wp-includes/formatting.php文件中复制代码代码如下:// This is not a tag, nor is the texturization ...

禁用wordpress gravatar应用本地头像进步网页关上速度

WordPress默许的头像是读取gravatar.com上的图片的,关于国际用户来说会使网页关上速度变慢。所以我决议删除...

WordPress应用自定义文章类型完成恣意模板的办法

本文实例讲述了WordPress应用自定义文章类型完成恣意模板的办法。分享给大家供大家参考,详细如下: 这几天...

需求提交

客服服务

亿鸽在线客服系统