wp load.php下载,WP 代码分析:wp-load.php

锺离阿苏
2023-12-01

简明现代魔法 -> WordPress -> WP 代码分析:wp-load.php

WP 代码分析:wp-load.php

2010-03-13

在上一篇文章中,我们知道,wp-blog-header.php 通过 wp-load.php 先后把 wp-config.php,wp-setting.php,classes.php,fucntions.php, query.php 等文件加载进来之后再建立三个全局变量,$wp_the_query,$wp_rewrite 和 $wp,分别为 WP_Query、 WP_Rewrite 和 WP 类的实例。

那么现在让我们分析下 wp-load.php:

/**

* Bootstrap file for setting the ABSPATH constant

这是设置 ABSPATH 常量和加载 wp-config.php 文件的引导文件

* 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.

wp-config.php 会加载 wp-settings.php 文件。

wp-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 文件没有找到,会提示一个一个错误,并让用户去建立一个 wp-config.php 文件。

* Will also search for wp-config.php in WordPress' parent

这个文件也会在 WordPress 目录下搜索 wp-config.php 文件,让 WordPress 的目录保持不变。

*

* @package WordPress

*/

/** Define ABSPATH as this files directory */

// dirname(__FILE__) 即当前路径,将'当前路径/' 定义为 ABSPATH

define( 'ABSPATH', dirname(__FILE__) . '/' );

if ( defined('E_RECOVERABLE_ERROR') )

error_reporting(E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING | E_RECOVERABLE_ERROR);

else

error_reporting(E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING);

// 如果当前目录下 wp-config.php 存在的话

if ( file_exists( ABSPATH . 'wp-config.php') )

{

/** The config file resides in ABSPATH */

require_once( ABSPATH . 'wp-config.php' );

}

// 如果 wp-config.php 不存在,并且 wp-settings.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

// Set a path for the link to the installer

if (strpos($_SERVER['PHP_SELF'], 'wp-admin') !== false) $path = '';

else $path = 'wp-admin/';

// Die with an error message

// 将以下文件包含进来,建立 wordpress 安装环境

require_once( ABSPATH . '/wp-includes/classes.php' );

require_once( ABSPATH . '/wp-includes/functions.php' );

require_once( ABSPATH . '/wp-includes/plugin.php' );

$text_direction = /*WP_I18N_TEXT_DIRECTION*/'从左到右'/*/WP_I18N_TEXT_DIRECTION*/;

wp_die(sprintf(/*WP_I18N_NO_CONFIG*/'看起来似乎没有 wp-config.php 文件。我们需要这个文件来让一切开始,可以查看更多帮助。 那么现在您可以通过这个 Web 界面创建一个 wp-config.php 文件,但并非所有主机都支持,安全的做法是手动创建。

试试创建一个配置文件'/*/WP_I18N_NO_CONFIG*/, $path), /*WP_I18N_ERROR_TITLE*/'WordPress › 错误'/*/WP_I18N_ERROR_TITLE*/, array('text_direction' => $text_direction));

}

?>

大概的意思就是,先检查当前目录下 wp-config.php 存不存在,存在的话就执行它。不存在的话就包含 classes.php、functions.php、plugin.php 这三个文件进来,组成 wordpress 的安装环境。安装环境具体怎么搭建我们可以以后再去了解,现在先要知道 wordpress 的运行机制,所以下一篇文章将会研究 wp-config.php 这个文件。

 类似资料: