2. wp-blog-header.php file analysis (a) the previous chapter we know that the index file only declares a confirmation to load the constant, then is containing wp-blog-header file wp-blog-header.php all content & lt ;? Phpif (! Isset ($ wp_did_header) {confirm access header $ II. wp-blog-header.php File Analysis (1)
In the previous chapter, we know that the index file only declares a constant to confirm loading, and then contains the wp-blog-header file.
// All wp-blog-header.php content
From the above code we can divide the wp-blog-header.php into three parts.
1. load the wp-load.php file in the current directory
2. call the wp () function
3. load the template-loder.php file under the wp-include Directory
We gradually analyze, starting from the wp-load.php, this file is also very simple, up to set the root directory and the way the error report, and then is to include the wp-config.php file.
Define ('abspath', dirname (_ FILE __). '/'); // wordpress Root Directory // check whether the wp-config.php file under the root directory exists. If yes, the '/' in the root directory constant will be removed and re-included. if you cannot find it, the installation page will be displayed. If (file_exists (ABSPATH. 'WP-config. php ') {require_once (ABSPATH. 'WP-config. php ');} elseif (file_exists (dirname (ABSPATH ). '/wp-config.php ')&&! File_exists (dirname (ABSPATH ). '/wp-settings.php') {require_once (dirname (ABSPATH ). '/wp-config.php');} else {// installation code, because do not study the installation, do not write}
We have installed wordpress by default here, so the program should smoothly load the wp-config.php file, which is the database configuration information and identity key, then the wp-setting.php file under the wp-include directory is loaded again.
// Database information and identity key is skipped // you can see, clearly defined in the wp-load.php file root directory constant, here due to the need to load the wp-settings.php and made a judgment, to avoid accidents, we need to learn this rigorous programming habit. If (! Defined ('abspath') define ('abspath', dirname (_ FILE _). '/');/** set WordPress variables and include files. */Require_once (ABSPATH. 'WP-settings. php ');