wp-load.php这文件可以算得上真正的开始初始化wordpress的运行的文件。最重要的就是设置了常量ABSPATH和加载了配置文件,配置文件中定义了数据库的信息。
该文件作用
定义常量 define(‘ABSPATH’, dirname(FILE). ‘/’);
设置错误的报告级别
加载配置文件, 如果配置文件不存在,将会安装程序。
定义的常量
define(‘ABSPATH’, dirname(FILE) . ‘/’);
定义的变量
$wp_did_header = true
定义的函数
无
定义的类
无
源码阅读1
/**
* Bootstrap file for setting the ABSPATH constant
* and loading the wp-config.php file. The wp-config.php
* file will then load the wp-settings.php file, which
* will then set up the WordPress environment.
*
* 引导文件设置了绝对路径 (ABSPATH) 常量,并且加载配置文件(wp-config.php), 配置文件加载设置文件(settings.php), 最终设置好wordpress的环境。
*
* If the wp-config.php file is not found then an error
* will be displayed asking the visitor to set up the
* wp-config.php file.
*
* 如果配置文件(wp-config.php)没有找到,就会告诉访问者设置一个配置文件。
*
* Will also search for wp-config.php in WordPress' parent
* directory to allow the WordPress directory to remain
* untouched.
*
* 关于文件wp-config.php的搜索, 当前的 ABSPATH目录下,没有找到,就是去父目录查找。
* #注# 配置文件保存了数据库信息,如果放在ABSPATH以外的目录,可能会更安全,因为是在web服务器之外,意思是不能通过url的方式访问。
* @package WordPress
*/
/** Define ABSPATH as this file's directory */
if (!defined('ABSPATH')) {
define('ABSPATH', dirname(__FILE__) . '/');
}
# 报告错误的级别
error_reporting(E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING | E_RECOVERABLE_ERROR);
源码阅读2
/*
* If wp-config.php exists in the WordPress root, or if it exists in the root and wp-settings.php
* doesn't, load wp-config.php. The secondary check for wp-settings.php has the added benefit
* of avoiding cases where the current directory is a nested installation, e.g. / is WordPress(a)
* and /blog/ is WordPress(b).
*
* 如果wp-config.php在wordpress的根目录存就加载配置文件,不存在,就去父目录里看看。
*
* If neither set of conditions is true, initiate loading the setup process.
* 如果两组(当前目录找不到配置文件, 父目录页找不到配置文件 )条件都不满足,就执行安装程序。
*/
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 {
// A config file doesn't exist
#注# 配置文件不存在就是会进入安装的wordpress的流程,这里就不分析了。