If you’re familiar WordPress you would already know that it has many uses. It can function as a blog, as a web store, or even as a business website among other things. Yet, how exactly does it work? If you’ve asked yourself and want to find out, you’re in luck! In this article, we give a tour of how WordPress works internally. This article is really text heavy but quite short, so need to worry if you think it may bore you.
With that being said, let’s proceed!
WordPress Internals Processes
1. Loading of ‘wp-config.php’
The first thing that happens is WordPress loads the ‘wp-config.php’ file. This file sets the global variables for the WordPress site. The most important of these are the database information.
2. Setting up of Default Constants
Once wp-config.php is loaded WordPress will set the default constants (these constants can be found and configured in the wp-config.php file)
3. Loading of ‘advanced-cache.php’
Once, the previous step is done, WordPress will check If ‘advanced-cache.php’ exists, If it does, it will be loaded next. ‘advanced-cache.php’ acts as a drop-in file. These are files that modify Core WordPress files.
4. Loading of ‘wp-content/db.php’
WordPress will then check If ‘wp-content/db.php’ exists, it will be loaded next. WordPress caching plugins use this file to improve the site’s database performance.
5. Connection to MySQL and Database Selection
After the previous step, WordPress will connect to MySQL and choose the appropriate database.
6. Loading of ‘object-cache.php’ or ‘wp-includes/cache.php’
WordPress will then try to load ‘object-cache.php’. If that doesn’t work, it would proceed to load ‘wp-includes/cache.php’
7. Loading of ‘wp-content/sunrise.php’
This step only works for a multisite network. If the current WordPress install is a multisite install, then ‘wp-content/sunrise.php’ will load.
8. Loading of ‘I10n.php’
WordPress will then load the ‘I!09.php’ which is used by WordPress to load the localizing system and language translation.
9. Loading of MultiSite Plugins
WordPress will then load all the plugins for a multisite install.
10. Execution of ‘muplugins_loaded’ Action
The ‘muplugins_loaded’ action is then executed. (An “action” is just a predefined function which is executed by WordPress). This action is only ran on multisite installs.
11. Loading of Active Plugins
After the previous step, WordPress will load the active plugins. To do this, WordPress checks the database for plugins with an “active” status and activates them. Otherwise, they are ignored.
12. Loading of ‘pluggable.php’
The ‘pluggable.php’ will be loaded next. This file searches for function with specific names in plugin files. If it cannot find them, it defines them in this file.
13. Execution of ‘plugins_loaded’ Action
WordPress will execute the ‘plugins_loaded’ action. This action allows developers to run the functions they created after loading all active plugins.
14. Loading of Rewrite Rules
After the previous step, WordPress will load the rewrite rules. Rewrite rules are used for routing.
15. Instantiation of ‘$wp_query’, ‘$wp_rewrite’, ‘$wp’ objects
WordPress will then instantiate the following ‘$wp_query’, ‘$wp_rewrite’, and ‘$wp_query’.
‘$wp_query’ is a global instance of WP_Query class. This class tells WordPress the requested content.
‘$wp_rewrite’ in a global instance of WP_Rewrite class. This class contains rewrite rules and functions for routing.
Lastly, ‘$wp’ is a global instance of the WP class. This class has functions for parsing requests and performing WordPress queries
16. Execution the ‘setup_theme’ Action
WordPress will then run the ‘setup_theme action. This actions is executed prior to the loading of a WordPress theme.’
17. Loading of Child’s and Parent’s Theme’s ‘functions.php’
‘functions.php’ file is then loaded after the theme is setup. If the current theme of a WordPress site is a child theme it will load the child theme’s ‘functions.php’. Afterwards, it will run the functions.php file of the parent theme.
18. Execution of ‘after_setup_theme’ Action
After the ‘setup_theme’ Action has been executed and the ‘functions.php’ files of the themes have been loaded, the ‘after_setup_theme’ would be loaded.
19. Setting Up of ‘Current User’ object.
WordPress will then load the ‘Current User’ object. This object determines what the logged-in user can do and what they have access to.
20. Execution of ‘init’ Action
At this point, WordPress has all the information it needs. It then executes the ‘init’ action which allows developers to add code that executes during this point in time.
21. Execution of ‘widget_init’ Action
WordPress then executes the ‘widget_init’ action which is used to register widgets and run code that the widget requires
22. Calling of ‘wp()’ function.
WordPress will then call the ‘wp()’ function which setups $wp, $wp_query, $wp_the_query (these are called “WordPress Query Globals”) . $wp->main is called after.
23. Parsing of User Request
WordPress, at this point, will parse the user request. To do this, it will first check the rewrite rules to match the request. Execution of query variable fillers, request action hook, and sends header request.
24. Run Queries
WordPress will load the query variables if the query is matched. Then it will run WP_Query->get_posts(). After that, it will execute ‘do_action_ref_array’ action with ‘pre_fet_posts’ as an argument and WP_Query as the second argument. WordPress will now run ‘apply_filter()’. WordPress will then fetch posts from the database. Subsequently the ‘posts_results’ and ‘the_posts’ filters.
If the query doesn’t match, WordPress will set the ‘is_404’ variable to ‘TRUE’
25. Execution of ‘template_redirect’ Action
WordPress will then run the ‘template_redirect’ Action. This executes prior to WordPress choosing which template to choose.
26. Loading of RSS Feed
WordPress will run the RSS feed if the content requested is that format
27. Loading Template
WordPress will look for the template file and load it.
28. Execution of ‘shutdown’ Action
WordPress lastly runs the ‘shutdown’ action to stop PHP code that is being executed. At this point in time WordPress would have generated the web page
Well that is all.
That’s all we need to know about how WordPress works internally. It might not be very detailed but should be sufficient as an overview of WordPress’s internals.
We hope that you learned from it!