WP initialization process: When you enter <yourlink>/wordpress to initialize wordpress, wordpress default will find
root directory of the index.php page, look at the index.php page.
<?php
Define (' Wp_use_themes ', true);
/** Loads the WordPress environment and Template * *
Require ('./wp-blog-header.php '); ---include/wp-blog-header.php in the
?> you will find that it will go to call the root directory under wp-blog-header.php, we continue to look at wp-blog-header.php.
<?php
if (!isset ($wp _did_header)) {
$WP _did_header = true;
Require_once (DirName (__file__). '/wp-load.php '); ---loading wp-load.php
WP (); ---loading function WP ();
Require_once (Abspath. Wpinc. '/template-loader.php '); ---loading template files
}
?>
Through wp-load.php,wordpress successively put wp-config.php, wp-setting.php,classes.php,fucntions.php,
Query.php and other files are loaded, and three global variables are created, $WP _the_query, $wp _rewrite and $WP, respectively, Wp_query,
Examples of wp_rewrite and WP classes. Then, Wp-blog-header executes the WP () function and invokes the main method of the WP class that $wp belongs to,
This method calls a series of methods, but the most important is the Parse_request method, where WP begins to parse the URL and establish the main loop.
Let's look at the main method of WordPress:
Function Main ($query _args = ") {
$this->init (); --Initializing the environment
$this->parse_request ($query _args); --Parse Request
$this->send_headers (); --Send header information
$this->query_posts (); --Query log
$this->handle_404 (); --operation 404 (URL address does not exist)
$this->register_globals (); --Register Global variables
Do_action_ref_array (' WP ', array (& $this));
}
This is basically the information when WordPress is initialized.
The following is a discussion of how WordPress works when we set up a custom permanent link.
When we use a custom permalink, WordPress will automatically generate the. htaccess file and create a phase in this file
Matching rules that correspond to permanent links, in wordpress/wp-includes/rewrite.php, have rewrite rules for. htaccess files, which
The $use_verbose_rules parameter specifies the detail and simplicity of the output information, false by default. The output information is relatively simple,
As follows
# BEGIN WordPress
<ifmodule mod_rewrite.c>
Rewriteengine on
Rewritebase/
Rewritecond%{request_filename}!-f
Rewritecond%{request_filename}!-d
Rewriterule. /index.php [L]
</IfModule>
# END WordPress
If you want to see the complete match rule, set $use_verbose_rules to True.
When WordPress uses a custom permalink for processing, it calls the Parse_request function in the wp-include/classes.php file to parse the request that was sent, regardless of whether it is a pathinfo type request. will be assigned to the $request parameter and then called to match the rules in. htaccess, and if a match is found, it will "Send header information", "Query Log" and return a 404 error if there is no match.
Bill: how WordPress Works