前回、ワードプレスが動くとき、どんなphpが動いているか2:wp-blog-header.phpで、requireされたwp-load.phpについて。
/**
* 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.
*
* 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.
*
* Will also search for wp-config.php in WordPress' parent
* directory to allow the WordPress directory to remain
* untouched.
*
* @package WordPress
*/
/** Define ABSPATH as this files directory */
define( 'ABSPATH', dirname(__FILE__) . '/' ); //*1
if ( defined('E_RECOVERABLE_ERROR') )
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);
else
error_reporting(E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING);
if ( file_exists( ABSPATH . 'wp-config.php') ) { //*2
/** 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' ) ) { //*3
/** The config file resides one level above ABSPATH but is not part of another install*/
require_once( dirname(ABSPATH) . '/wp-config.php' );
} else { //*4
// 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
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*/'ltr'/*/WP_I18N_TEXT_DIRECTION*/;
wp_die(sprintf('ファイルが見つかりません。インストールを開始するにはwp-config.php ファイルが必要です。お困りでしたら「wp-config.php の編集」を参照してください。ウィザード形式で wp-config.phpファイルを作成することもできますが、すべてのサーバーにおいて正常に動作するわけではありません。最も安全な方法は手動でファイルを作成することです。<a href="setup-config.php" class="button">設定ファイルを作成する</a>', $path),'WordPress › エラー', array('text_direction' => $text_direction));
}
上部のコメントの大体訳。
- ABSPATH=絶対パスを設定します。
- 次にwp−config.phpファイルを読み込みます。
- wp-config.phpはwp-setting.phpを読み込みます。
- wp-setting.phpはWordPressの環境設定をしてくれます。
- wp-config.phpが見当たらなければ、エラーメッセージと一緒に、wp-config.phpを作るかどうかを聞きます。
- もしかして、一個上の階層にあるかもしれないので、色々やってます
処理
*1で、「今後ABSPATHと書いたらここの階層(root/wordpress/)のことですよ」と決める。
define( 'ABSPATH', dirname(__FILE__) . '/' );
以下、config.phpが有るか無いかで、処理を条件分岐させてます。
*2で、もしconfig.phpがあれば呼び出し。
if ( file_exists( ABSPATH . 'wp-config.php') ) {
require_once( ABSPATH . 'wp-config.php' );
すでに、インストールが済んでいる場合はこの処理になる。
*4で、config.phpが見当たらない場合はエラー出しつつ作るか聞く。
途中、$pathを決めるための処理が挟まっててややこしい。
エラーメッセージの直前に、インストールをするために必要なクラス、関数、pluginファイルを読み込んでいる。
else { //*4
// 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
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*/'ltr'/*/WP_I18N_TEXT_DIRECTION*/;
wp_die(sprintf('ファイルが見つかりません。インストールを開始するにはwp-config.php ファイルが必要です。お困りでしたら「wp-config.php の編集」を参照してください。ウィザード形式で wp-config.phpファイルを作成することもできますが、すべてのサーバーにおいて正常に動作するわけではありません。最も安全な方法は手動でファイルを作成することです。<a href="setup-config.php" class="button">設定ファイルを作成する</a>', $path),'WordPress › エラー', array('text_direction' => $text_direction));
}
*3は、一個上の階層にwp-config.phpがあった場合の処理。
wp-load.phpの役割
正常にインストールされていれば、そのまま進み(wp-setting.phpへ)、されてなければsetup-config.phpに移動させる。
コメント