<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Stijn De Lathouwer on Medium]]></title>
        <description><![CDATA[Stories by Stijn De Lathouwer on Medium]]></description>
        <link>https://medium.com/@dendeffe?source=rss-b051a4b25c52------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*xfr7W-vCk6bT--tT.jpg</url>
            <title>Stories by Stijn De Lathouwer on Medium</title>
            <link>https://medium.com/@dendeffe?source=rss-b051a4b25c52------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 04:17:35 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dendeffe/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[WordPress: admin-footer]]></title>
            <link>https://medium.com/@dendeffe/wordpress-admin-footer-bfee5ae11823?source=rss-b051a4b25c52------2</link>
            <guid isPermaLink="false">https://medium.com/p/bfee5ae11823</guid>
            <category><![CDATA[php]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[worpress]]></category>
            <dc:creator><![CDATA[Stijn De Lathouwer]]></dc:creator>
            <pubDate>Wed, 17 Jun 2015 12:43:32 GMT</pubDate>
            <atom:updated>2015-06-17T12:43:32.745Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/470/1*ZzoO5Yv0WxCjJdxnpvkyvQ.jpeg" /></figure><p>Our <a href="https://medium.com/@dendeffe/wordpress-admin-header-51fa07fddf62">treacherous trip</a> into the back country of admin-header.php is followed by a more leisurely stroll through admin-footer.php. In comparison, admin-footer is a really small file.</p><p>First, is a check to avoid someone opening the file directly (by checking if the ABSPATH constant is set).</p><p>Then, we have a few div closing tags (which were started in admin-header).</p><h3>Hooks and Filters</h3><p>The meat of admin-footer sits in the hooks and filters. Here’s a list of what they do:</p><ul><li>in_admin_footer: (hook) Add functions within the wpfooter div</li><li>admin_footer_text: (filter) Here you can change (or remove) the <em>Thank You</em> text.</li><li>update_footer: (filter) WordPress filters this to show your WordPress version (or an update message if you need to update).</li><li>admin_footer: (hook) You can use it to do actions just before the footer scripts (enqueued to the bottom) are run. WordPress itself hooks into this as well, see _admin_notice_post_locked, used to notify users that someone else is editing the current post.</li><li>admin_print_footer_scripts: (hook) This is used to enqueue the scripts that you designate to the footer.</li><li>“admin_footer-” . $GLOBALS[‘hook_suffix’]: (hook) This last hook is based on the specific admin page you are loading.</li></ul><p>At the bottom of admin-footer, wpOnload() is run. Note that this function will only exist if jQuery’s (document).ready() can not be used.</p><p>And that pretty much wraps it up for admin-footer.php. See? That wasn’t too hard after all.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bfee5ae11823" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[WordPress: admin-header]]></title>
            <link>https://medium.com/@dendeffe/wordpress-admin-header-51fa07fddf62?source=rss-b051a4b25c52------2</link>
            <guid isPermaLink="false">https://medium.com/p/51fa07fddf62</guid>
            <category><![CDATA[wordpress]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Stijn De Lathouwer]]></dc:creator>
            <pubDate>Wed, 17 Jun 2015 09:27:35 GMT</pubDate>
            <atom:updated>2015-06-17T12:46:14.289Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/470/1*ZzoO5Yv0WxCjJdxnpvkyvQ.jpeg" /><figcaption><em>Welcome to the WordPress jungle.</em></figcaption></figure><p>Let’s continue our descent into the murky depths of the WordPress jungle. We have arrived at <a href="https://github.com/WordPress/WordPress/blob/master/wp-admin/admin-header.php">wp-admin/admin-header.php</a><br>This is called on pretty much every admin page in WordPress. That’s why I promised to go over it in <a href="http://defunkt.nu/blog-en/wordpress-loading-sequence-the-wp-admin-edition/">my previous WP Jungle article</a>.</p><h3>HTTP HEADER</h3><p>First, it sets the http header. It uses the options (html_type and blog_charset) that are set in the database (in wp-options.php). In case you wondered how these values got there, WordPress inserts them during the install procedure. You can check <a href="http://defunkt.nu/blog-en/wordpress-loading-sequence-the-wp-admin-edition/#https://github.com/WordPress/WordPress/blob/master/wp-admin/includes/schema.php">wp-admin/includes/schema.php</a> for the complete SQL.</p><h3>MAKING SURE SETUP HAS BEEN DONE</h3><p>Next, WordPress checks if the constant WP_ADMIN has been set. If not, the bootstrap for admin sections is loaded.</p><p>If admin-header.php is being included from within a function, the variables defined in the loading process ($hook_suffix etc…) are not available. That’s why the global variables are explicitly referenced.</p><p>Another check follows, to see if <strong>$current_screen</strong> has been populated.</p><h3>BUILDING THE $ADMIN_TITLE</h3><p>Most times, $title will have been populated (by the admin bootstrap) and nothing will happen in get_admin_page_title().<br>After this last check, $admin_title is built, followed by the filter ‘admin_title’, which gives you the opportunity to change it.</p><h3>WP_USER_SETTINGS()</h3><p>In the <a href="http://defunkt.nu/blog-en/wordpress-loading-sequence-the-wp-admin-edition/#https://github.com/WordPress/WordPress/blob/master/wp-admin/includes/schema.php">previous article</a>, we covered screen options (how many pages to display, which columns in the …). They are stored in the wp_usermeta table. One special entry in wp_user_meta is <strong>wp_user-settings</strong>. These are options that are persistent across the whole admin interface.</p><p>For instance, say I chose to use the tradional media uploader in Media. Afterwards, I collapse the Admin sidebar. WordPress will save these settungs in wp_user_meta as:</p><ul><li>user_id = current user’s id</li><li>meta_key = wp_user-settings</li><li>meta_value = a url string of all options</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*p6uN_IL2RB_b-_NR.jpg" /></figure><p>(Click the image for a larger version)</p><p>To avoid another call to the database on every admin page, this query string is also stored in a cookie. The wp_user_settings() function (located in <a href="https://github.com/WordPress/WordPress/blob/master/wp-includes/option.php">option.php</a>), checks if the cookie needs to be renewed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/568/0*4sfFzvFMXfwBXq9Y.jpg" /></figure><h3>_WP_ADMIN_HTML_BEGIN()</h3><p>This is a pretty simple function. It outputs</p><ul><li>the doctype</li><li>the html opening tag</li><li>the head tag</li><li>a meta tag for Content-Type</li></ul><p>It has two extra’s: a conditional comment for IE8 and a hook to output the XML namespace (if you should need it).</p><h3>LOADING STYLESHEETS AND SCRIPTS</h3><p>Next, you see two styles (colors and ie) and two scripts (utils and svg-painter) being enqueued. The fact that these are enqueued without a URL, means that WordPress already knows what files to load. The styles (or scripts) are already registered. If you do a dump of $wp_styles (make sure you refer the global), you indeed see that <a href="https://gist.github.com/dendeffe/05c677c29fdb8b4a2f18">there is an object</a> with the references to the styles.</p><p>Whenever you try to enqueue or register a new style, WordPress checks if a WP_Styles object already exists. If it doesn’t find one, it creates one.</p><p>In it’s __construct(), the WP_Styles class has a hook called <a href="https://github.com/WordPress/WordPress/blob/master/wp-includes/class.wp-styles.php#L39">wp_default_styles</a> — It is hooked from <a href="https://github.com/WordPress/WordPress/blob/master/wp-includes/default-filters.php#L365">wp-includes/default-filters.php</a>. The function it references (wp_default_styles) is located in <a href="https://github.com/WordPress/WordPress/blob/master/wp-includes/script-loader.php#L613">wp-includes/script-loader.php</a></p><p>It then uses the add method (Wp_Styles extends <a href="https://github.com/WordPress/WordPress/blob/master/wp-includes/class.wp-dependencies.php#L218">WP_Dependencies</a>) To correctly add the default styles to the global $wp_styles object.</p><p>On most admin pages, colors is not the first enqueued style. <a href="https://github.com/WordPress/WordPress/blob/master/wp-includes/admin-bar.php#L21">_wp_admin_bar_init (in wp-includes/admin-bar.php) </a>enqueues the styles for the admin bar. This is hooked on admin_init and will (most of the times) be the function that builds the WP_Styles object.</p><p>Note that colors is also a special case. In <a href="https://github.com/WordPress/WordPress/blob/master/wp-includes/script-loader.php#L775">wp_style_loader_src</a>, WordPress checks if the user has a specific color scheme (stored in a user option). If so, an extra CSS file is loaded.</p><p>The IE stylesheet has (as one would expect) some fixes for IE7 (yay backwards compatibility!). As for the scripts:</p><ul><li><a href="https://github.com/WordPress/WordPress/blob/master/wp-includes/js/utils.js">utils.js</a> — provides cookie functionality and functions to save the user settings</li><li><a href="https://github.com/WordPress/WordPress/blob/master/wp-admin/js/svg-painter.js">svg-painter.js</a> — most icons in the admin come from Dashicons — however, <a href="https://make.wordpress.org/design/2013/08/31/mp6-2-0/">it is also possible to use an .svg</a> — These functions try to do the correct recoloring for SVG icons.</li></ul><p>The next step is calculating the admin_body_class. This is done based on the $hook_suffix (see <a href="http://defunkt.nu/blog-en/wordpress-loading-sequence-the-wp-admin-edition/">previous article</a>).</p><h3>ADDLOADEVENT</h3><p>WordPress then provides a sort of standardized way to load functions when your page has is loaded. You can pass a function into it: addLoadEvent(my_function); WordPress will then first try to use jQuery(document).ready. Failing so, it creates it’s own wpOnload function (or your function is added to an existing wpOnload).</p><h3>GLOBAL JAVASCRIPT VARIABLES</h3><p>WordPress now prints out a series of global variables (that were already available in PHP) for JavaScript. This includes the Ajax URL (which always should go through wp-admin).</p><h3>HOOKS FOR STYLE AND SCRIPT LOADING</h3><p>Next, you’ll see a series of hooks to load custom stylesheets and scripts (from plugins and themes).</p><ul><li>admin_enqueue_scripts (used to load your scripts/stylesheets on every admin page)</li><li>admin_print_styles-$hook_suffix (this fires when the styles for a specific admin page are actually printed (written tohtml). It doesn’t fit into the normal enqeueing, so it shouldn’t be used to add your own scripts and styles).</li><li>admin_print_styles (same as the above one, but fires on every admin page)</li><li>admin_print_scripts-$hook_suffix (same as the one for styles — note there is also an action in admin-footer.php for scripts that are enqueued to the bottom).</li><li>admin_print_scripts (same as the one for styles — note there is also an action in admin-footer.php for scripts that are enqueued to the bottom)</li></ul><h3>BUILDING UP TO THE BODY ELEMENT</h3><p>Almost at the body element now! First, there are two admin_head hooks. One specific to the page type (based on $hook_suffix), followed by a global one.</p><p>WordPress now adds a load of HTML classes to a variable ($admin_body_class). They include user options (menu folded), if the writing direction is RTL, the WordPress version…</p><p>Afterwards, you get a filter (admin_body_class) to add your own classes.</p><p>Both are added to the body element. WordPress also adds a no-js class which is is immediately removed with an inline script (actually the first thing in the body).</p><h3>REMOVING THE NO-CUSTOMIZE SUPPORT</h3><p>The customizer needs to have this class set to customize as early as possible to prevent Flash of Unstyled content.</p><h3>SHOWING THE MENU</h3><p>WordPress now adds a tab index (for accessibility).</p><p>This is followed by requiring a file (wp-admin/menu-header.php) that is responsible for displaying the (sidebar) menu for the admin. (Remember the menu was built in wp-admin/menu.php, which was called from wp-admin/admin.php).</p><p>The first hook (at the start of the admin content) is in_admin_header. It is used to load the admin bar.</p><p>After the admin bar is loaded, WordPress deletes some variables that were used in the admin bar.</p><h3>DETERMENING THE PARENT FILE</h3><p>Each admin page determines a parent, even if it is a top level page (in the menu). A string (without the .php extension and without query variables is saved to the Screen object).</p><h3>ADMIN NOTICES</h3><p>The Screen object then loads a method for old plugins that use deprecated ways of manipulating the help menu.</p><p>You now get a few hooks to add <a href="https://codex.wordpress.org/Plugin_API/Action_Reference/admin_notices">admin notices</a> (when publishing a post etc…)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=51fa07fddf62" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[WordPress loading sequence: the wp-admin edition]]></title>
            <link>https://medium.com/@dendeffe/welcome-to-another-instalment-of-my-wordpress-jungle-tours-through-the-backwaters-of-wp-e9299e689286?source=rss-b051a4b25c52------2</link>
            <guid isPermaLink="false">https://medium.com/p/e9299e689286</guid>
            <category><![CDATA[php]]></category>
            <category><![CDATA[wordpress]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Stijn De Lathouwer]]></dc:creator>
            <pubDate>Wed, 17 Jun 2015 09:23:56 GMT</pubDate>
            <atom:updated>2015-06-17T12:45:53.414Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/470/1*ZzoO5Yv0WxCjJdxnpvkyvQ.jpeg" /><figcaption><em>Welcome to the WordPress jungle.</em></figcaption></figure><p>Welcome to another instalment of my WordPress Jungle tours through the backwaters of WP.</p><p>This article builds upon <a href="http://defunkt.nu/blog-en/wordpress-loading-sequence-a-guided-tour">my previous walkthrough of the WordPress loading process</a>. If you log into the admin, the address is yoursite.com/wp-admin. That URL doesn’t do an .htaccess redirect, you actually load the<a href="https://github.com/WordPress/WordPress/blob/master/wp-admin/index.php">index.php</a> in the wp-admin folder.</p><h3>ADMIN.PHP</h3><p>The first thing it does, is load <a href="https://github.com/WordPress/WordPress/blob/master/wp-admin/admin.php">wp-admin/admin.php</a> — This is the file that bootstraps the admin. It sets up a few constants to let the rest of the system know you are in the admin. Then, it loads up our trusty <a href="https://github.com/WordPress/WordPress/blob/master/wp-load.php">wp-load.php</a>, which loads wp-config, which loads <a href="https://github.com/WordPress/WordPress/blob/master/wp-settings.php">wp-settings.php</a>and boots up the entire WordPress application. (<a href="http://defunkt.nu/blog-en/wordpress-loading-sequence-a-guided-tour">see the previous article for more details on how this works</a>).</p><p>The big difference is that admin.php doesn’t start the <a href="https://github.com/WordPress/WordPress/blob/master/wp-includes/class-wp.php">wp object</a> to populate a query and it doesn’t use the <a href="https://github.com/WordPress/WordPress/blob/master/wp-includes/template-loader.php">template loader</a> from the front end. So let’s go through admin.php for the rest of this article.</p><h3>NOCACHE HEADER AND A CHECK FOR A DATABASE UPGRADE</h3><p>WordPress now makes sure your browser doesn’t load a cached version of the admin page.</p><p>It also checks if a database upgrade has been done (or you are in the middle of upgrading multisite). You get a few hooks and filters here to interact with the process.</p><h3>WP-ADMIN/INCLUDES/ADMIN.PHP</h3><p>At this point the ‘normal’ part of the WordPress application has already loaded (through wp-settings.php). Admin now loads extra files with all the specific admin functions and classes. This happens in <a href="https://github.com/WordPress/WordPress/blob/master/wp-admin/includes/admin.php">wp-admin/includes/admin.php</a></p><h3>AUTH_REDIRECT()</h3><p>After loading all the extra function files, we’re back in wp-admin/wp-admin.php! auth-redirect() is a <a href="https://codex.wordpress.org/Pluggable_Functions">pluggable function</a> that checks if the user is logged in. If not, he is redirected to a log in screen. <strong>Bonus tip:</strong> you can add this function to your own templates for a quick and dirty protected page type.</p><h3>WP_SCHEDULED_DELETE()</h3><p>This function is run through <a href="https://github.com/WordPress/WordPress/blob/master/wp-includes/cron.php">WordPress Cron</a> and checks if there are posts that are in your trash for longer than the maximum time you have set. If so, it permanently deletes them.</p><h3>SET_SCREEN_OPTIONS()</h3><p>This function saves the options you set in the ‘screen options’ drop down at the top of admin screens. These options are stored in the usermeta table.</p><p>WordPress then loads the date and time format from wp_options. You set these values in your admin (Settings &gt; General).</p><h3>COMMON.JS</h3><p>WordPress now enqueues wp-admin/js/common.js, which is responsible for things like displaying tables, validating forms,…</p><h3>$EDITING VARIABLE</h3><p>The editing variable is set to false here. If you are in <a href="https://github.com/WordPress/WordPress/blob/master/wp-admin/post.php">post.php</a> or <a href="https://github.com/WordPress/WordPress/blob/master/wp-admin/post-new.php">post-new.php</a>, it is set to true. These are set to edit/create any kind of post type.<br>I have not found any other reference for the $editing reference. I guess it is only there for plugins to check.</p><h3>DETERMINING WHICH PAGE IS BEING LOADED</h3><p>Next, a few variables are set to determine which admin screen is loaded.</p><p>If the selected <a href="https://codex.wordpress.org/Administration_Menus">admin page was added through a plugin</a>, the URL-variable is saved in <strong>$plugin_page</strong>.</p><p>If you are editing or adding a post type (other than the default: post), it’s post type is saved in <strong>$typenow</strong>.</p><p>A last URL variable which is checked and saved is taxonomy. You get this if you open a taxonomy overview or if you are editing one. It is saved into <strong>$taxnow</strong>.</p><h3>BUILDING THE MENU</h3><p>Most pages then just load <a href="https://github.com/WordPress/WordPress/blob/master/wp-admin/menu.php">wp-admin/menu.php</a>. Two special cases (multisite and a user editing his profile) load a different menu file (which then at the end requires <a href="https://github.com/WordPress/WordPress/blob/master/wp-admin/menu.php">wp-admin/menu.php</a>).</p><p><a href="https://github.com/WordPress/WordPress/blob/master/wp-admin/menu.php">wp-admin/menu.php</a> builds a big menu array and at the end, it requires <a href="https://github.com/WordPress/WordPress/blob/master/wp-admin/includes/menu.php">wp-admin/includes/menu.php</a>.</p><p>That last file provides extra filters and hooks and filters to customize the menu before it is output to the browser.</p><h3>INCREASE MEMORY LIMIT</h3><p>WordPress now checks if you are an admin (current_user_can). If so, the PHP memory limit is increased temporarily. This may be necessary for certain admin scripts. You also get a filter here which you can use from you plugin to override the constant.</p><h3>ADMIN_INIT</h3><p>You now get the admin_init hook. It is comparable to the init hook (from the regular loading sequence). The admin loading process is over and all extra admin functions are available.</p><h3>SETTING $PAGE_HOOK AND $HOOK_SUFFIX</h3><p>If the page we want to access was added through a plugin, WordPress will now create a custom hook for it: <strong>$page_hook</strong>.</p><p>If you need a quick and (very) dirty way of seeying your current $page_hook, you could add<a href="https://gist.github.com/dendeffe/d2d8b7971f6d446a0b77">this snippet</a> in your functions.php.</p><p>The $hook_suffix variable is used to create extra hooks throughout the admin files. For instance in <a href="https://github.com/WordPress/WordPress/blob/master/wp-admin/admin-footer.php">admin-footer.php</a> and <a href="https://github.com/WordPress/WordPress/blob/master/wp-admin/admin-header.php">admin-header.php</a></p><h3>SET_CURRENT_SCREEN</h3><p>WordPress will now store a <a href="https://github.com/WordPress/WordPress/blob/master/wp-admin/includes/screen.php">WP_Screen</a> object in $current_screen. The properties for this object are calculated (in the get method of WP_Screen) based on the $hook_suffix variable (see above).</p><p>The object in $current_screen will also let you interact with things like the help tabs.</p><h3>PLUGIN PAGE</h3><p>If the admin page you are trying to view is a page added by a plugin, you now get a <strong>load-$page_hook</strong> action and a <strong>$page_hook</strong> action you can call. In the comments here, you’ll also see how the $page_hook is calculated.</p><h3>IMPORTING</h3><p>Another special case is when you are importing. WordPress checks if you are calling a proper importer (among other things).</p><h3>HOOK ONTO $PAGENOW</h3><p>One of the last hooks in this bootstrap file: <strong>load-$pagenow</strong>. As you see from the if-else statements, this will only fire if it is not a page created by a plugin (those have the $page_hook).</p><h3>HOOK FOR REQUEST ACTION</h3><p>If your page provides an action value in $_REQUEST, you can hook into it with add_action(‘admin_action_youraction’, ‘yourfunction’);</p><h3>AFTER LOADING ADMIN.PHP</h3><p>After loading wp-admin/admin.php, you have to look into the requested admin file. There you’ll see how it works (unless it is a plugin page, which is handled in admin.php, as we have seen).</p><p>The dashboard (wp-admin/index.php), for instance, loads the dashboard widgets and sets up help tabs (through WP_Screen).</p><p>I plan on going through a selected range of admin pages in future articles.</p><p>What most have in common, though, is that they call wp-admin/admin-header.php and wp-admin/admin-footer.php</p><p>Those two files will probably be a subject of my next article.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e9299e689286" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[WordPress loading sequence: A guided tour]]></title>
            <link>https://medium.com/@dendeffe/wordpress-loading-sequence-a-guided-tour-e077c7dbd119?source=rss-b051a4b25c52------2</link>
            <guid isPermaLink="false">https://medium.com/p/e077c7dbd119</guid>
            <category><![CDATA[php]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[wordpress]]></category>
            <dc:creator><![CDATA[Stijn De Lathouwer]]></dc:creator>
            <pubDate>Wed, 17 Jun 2015 09:18:34 GMT</pubDate>
            <atom:updated>2015-06-17T12:45:09.773Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/470/1*ZzoO5Yv0WxCjJdxnpvkyvQ.jpeg" /><figcaption>Welcome to the WordPress jungle.</figcaption></figure><p>True enough, WordPress can be a bit of a jungle. It has grown organically from a blogging platform to a CMS platform. At the moment, I’m hacking my way through the API’s, loading process,… And I plan on documenting it in a series of articles.</p><h3>FIRST FILES</h3><p>As it is a PHP program, the first thing to load is index.php in the root folder.</p><p>This file doesn’t do much on it’s own. It defines a constant and loads the file <a href="https://github.com/WordPress/WordPress/blob/master/wp-blog-header.php">wp-blog-header.php</a> in the same folder.</p><p>If you load an admin page, you start at <a href="https://github.com/WordPress/WordPress/blob/master/wp-admin/index.php">wp-admin/index.php</a> instead. The admin loading process then also uses the ‘normal’ process (with some extra’s).</p><h3>WP-BLOG-HEADER.PHP</h3><p><a href="https://github.com/WordPress/WordPress/blob/master/wp-blog-header.php">wp-blog-header.php</a> does three things. It loads <a href="https://github.com/WordPress/WordPress/blob/master/wp-load.php">wp-load.php</a> which sets up the entire WordPress environment. Then, it executes the wp() function in <a href="https://github.com/WordPress/WordPress/blob/master/wp-includes/functions.php">wp-includes/functions.php</a>which loads the query. <a href="https://github.com/WordPress/WordPress/blob/master/wp-includes/template-loader.php">template-loader.php</a> decides which template should be loaded.</p><h3>WP-LOAD.PHP</h3><p>This file checks for <strong>wp-config.php</strong> if it finds one, it continues the environment setup process. If there is no wp-config.php, Wordpress assumes it’s a new installation. It then loads the installation screen.</p><p>At the end of every <strong>wp-config.php</strong> file, there is a require for <a href="https://github.com/WordPress/WordPress/blob/master/wp-settings.php">wp-settings.php</a>. This is where the setup process starts for real.</p><h3>WP-SETTINGS.PHP</h3><p>At the top of this file, three other files are loaded:</p><ul><li><a href="https://github.com/WordPress/WordPress/blob/master/wp-includes/load.php">load.php</a> (in wp-includes) — This provides the first functions that WordPress needs. Most of them deal with normalizing the server, checking if maintenance mode is active, checking if debug mode is active, etc…</li><li><a href="https://github.com/WordPress/WordPress/blob/master/wp-includes/default-constants.php">default-constants.php</a> (also in wp-includes) — Sets up a lot of constants. If they are not defined in wp-config.php</li><li><a href="https://github.com/WordPress/WordPress/blob/master/wp-includes/version.php">version.php</a> (again, wp-includes) — Really simple file that defines versions/required versions</li></ul><h3>FUNCTIONS.PHP, WP CLASSES AND THE PLUGIN API</h3><p>Wordpress then runs functions from <a href="https://github.com/WordPress/WordPress/blob/master/wp-includes/load.php">load.php</a>. These first functions are mostly used to ‘nomalize’ the server.</p><p>From the comment <strong>Load early WordPress files</strong>, the first functions are loaded that do more than setting things up.</p><p><a href="https://github.com/WordPress/WordPress/blob/master/wp-includes/compat.php">compat.php</a> adds some extra functions missing from older PHP-versions. WordPress is really dedicated to support really old PHP-versions.</p><p><a href="https://github.com/WordPress/WordPress/blob/master/wp-includes/functions.php">functions.php</a> is where the most basic functions to run your site. They include functions for serializing data (post_meta for instance), date functions, dealing with get queries, nonces and more…</p><p><a href="https://github.com/WordPress/WordPress/blob/master/wp-includes/class-wp.php">class-wp.php</a> actually builds the query, processes query vars and sets up. It is an object that is instantiated near the end of <a href="https://github.com/WordPress/WordPress/blob/master/wp-settings.php">wp-settings.php</a></p><p><a href="https://github.com/WordPress/WordPress/blob/master/wp-includes/class-wp-error.php">class-wp-error.php</a> is a class that can be used in your own plugins to keep track of errors. It was introduced as a replacement for try/catch and returns specific WP_Error objects.</p><p>Now <a href="https://github.com/WordPress/WordPress/blob/master/wp-includes/plugin.php">plugin.php</a> is loaded. That is another important file. It provides the functions that are needed for the <a href="https://codex.wordpress.org/Plugin_API">action and filter hooks</a>. These allow to alter behaviour of the core files and plugins without touching the original code.</p><p>Lastly in this series of requires, WordPress loads <a href="https://github.com/WordPress/WordPress/blob/master/wp-includes/pomo/mo.php">mo.php</a> to work with translation files.</p><h3>SETTING UP THE DATABASE CLASS AND CACHE</h3><p>Then, require_wp_db() and wp_start_object_cache() are called (from <a href="https://github.com/WordPress/WordPress/blob/master/wp-includes/load.php">load.php</a>). They provide connections to the database and caching. They also allow you to use <a href="https://hakre.wordpress.com/2010/05/01/must-use-and-drop-ins-plugins/">drop-ins</a>. This means that you can substitute the default classes and functionality here.</p><h3>DEFAULT-FILTERS.PHP</h3><p><a href="https://github.com/WordPress/WordPress/blob/master/wp-includes/default-filters.php">This is a file</a> which sets up a lot of <a href="https://codex.wordpress.org/Plugin_API">filters and actions</a>. This is really interesting. You can check this list for the priorities to remove them.</p><h3>MULTISITE STARTUP</h3><p>If you set multisite in wp-config, WordPress now loads the necessary functions (<a href="https://github.com/WordPress/WordPress/blob/master/wp-includes/ms-blogs.php">ms-blogs.php</a>) and starts up everything necessary for multisite (<a href="https://github.com/WordPress/WordPress/blob/master/wp-includes/ms-settings.php">ms-settings.php</a>, which is similar in concept to wp-settings). Also note that ms-settings can load a sunrise.php dropin that can change how multisite works.</p><h3>END OF BASIC LOADING</h3><p>WordPress is now done loading it’s main functions. It adds a hook (<strong>shutdown_action_hook</strong>) that is run after PHP shuts down (through <a href="http://php.net/manual/en/function.register-shutdown-function.php">register_shutdown_function</a>).</p><p>The hook is defined here, because right after it, there is a check for the <strong>SHORTINIT</strong>constant. You can define this constant in your plugins or themes if you only need to load the very basics of WordPress. <a href="http://kynatro.com/blog/2012/12/11/finally-a-practical-use-for-wordpress-secret-shortinit-constant/">For instance if you want to speed up Ajax calls or are building some sort of API on top of WordPress</a>.</p><p>Note that a lot of expected WordPress functionality is not yet available at this point, including using plugins.</p><h3>LOADING MOST OF WORDPRESS</h3><p>The <a href="https://github.com/WordPress/WordPress/blob/master/wp-includes/l10n.php">translation API</a> is loaded and WordPress does a final check to see if the site needs to be installed.</p><p>The long list of requires that follow loads all functions and classes that give you the full WordPress core functionality. It is an eclectic mix of functions and classes, providing functionality like building menu’s, right and user management and much more. Each of these files warrants a blog post to cover the way they work.</p><h3>LOADING MUST USE PLUGINS</h3><p>Before loading must use plugins, extra default constants are set which need more of the API loaded than the ones set with wp_initial_constants at the beginning of the wp-settings.</p><p><a href="https://hakre.wordpress.com/2010/05/01/must-use-and-drop-ins-plugins/">Must use plugins</a> are plugins that you won’t manage through the normal plugin admin screens. They are useful if you are building an application in which it makes no sense that end users would enable/disable parts of the application.</p><p>Another use for must use plugins is a plugin that loads before all other plugins, because the normal plugins are only loaded further on in wp-settings.</p><p>After loading the must use plugins, you get the earliest hook you can call:<a href="https://codex.wordpress.org/Plugin_API/Action_Reference/muplugins_loaded">muplugins_loaded</a> — Note that there still are no ‘normal’ plugins loaded at this point.</p><h3>DEFAULT TAXONOMIES AND POST TYPES</h3><p>WordPress now sets up a bunch of extra constants and variables (which include the User Agent, if the site is using SSL and more).</p><p>It then goes on to set up the default <a href="https://github.com/WordPress/WordPress/blob/master/wp-includes/post.php">post types</a> and <a href="https://github.com/WordPress/WordPress/blob/master/wp-includes/taxonomy.php">taxonomies</a> (Post, Page, Attachment, Category, Tag,…)</p><h3>LOADING THE NORMAL PLUGINS</h3><p>After setting the theme directory, WordPress loads the ‘normal’ plugins, as defined in the option active_plugins. It also loads <a href="https://github.com/WordPress/WordPress/blob/master/wp-includes/pluggable.php">pluggable</a>, which includes <a href="https://codex.wordpress.org/Pluggable_Functions">funtions you can easily overwrite from your themes or plugins</a>.</p><p>With all the plugins loaded, you get another early hook: <a href="https://codex.wordpress.org/Plugin_API/Action_Reference/plugins_loaded">plugins_loaded</a>. At this point, all plugins are loaded and their functions and hooks are available to you.</p><h3>CREATING THE GLOBAL OBJECTS</h3><p>WordPress now creates objects (wp, wp_query,…) which become globally available. These hold things like the current query.</p><h3>CHOOSING THE THEME</h3><p>WordPress now checks which theme is active and loads the <strong>functions.php</strong> file for the theme. Also note that there are two extra hooks here, <a href="http://codex.wordpress.org/Plugin_API/Action_Reference/setup_theme">one before the theme is selected</a> and<a href="https://codex.wordpress.org/Plugin_API/Action_Reference/after_setup_theme">one that is run afterwards</a>.</p><h3>INIT HOOK</h3><p>The WP object now runs it’s init action, which populates the current user. After that is done, you get the famous <a href="https://codex.wordpress.org/Plugin_API/Action_Reference/init">init hook</a>. Loads of plugins and themes use this hook. The entire core of WordPress functions is loaded and the current user is populated.</p><h3>WP_LOADED HOOK</h3><p>If your site is a multisite, WordPress will check if the current site is a fully active.</p><p>So if you have a multi site (or want to fire a function after most plugins have loaded) the<a href="https://codex.wordpress.org/Plugin_API/Action_Reference/wp_loaded">wp_loaded</a> hook is a good one to use.</p><p>You might have thought it may never end, but this actually concludes wp-settings.php</p><h3>WP()</h3><p>At this stage, all core functions are available and WordPress is loaded. Nothing has yet been written to the browser, however.</p><p>Remember <a href="https://github.com/WordPress/WordPress/blob/master/wp-blog-header.php">wp-blog-header.php</a> ? It requires wp-load.php (which requires wp-config.php, which in turn requires wp-settings.php, which loads the entire WordPress API and brought us to this point).</p><p>Now the wp() function (in wp-includes/functions.php) is run. It uses the <a href="https://github.com/WordPress/WordPress/blob/master/wp-includes/class-wp.php">WP object</a> and runs it’s main action. This checks the URL and builds the needed query to get the data needed for this page.</p><h3>TEMPLATE-LOADER.PHP</h3><p>Now for the final part of our booting process. All functions are available (wp-settings.php) and the required data is loaded (wp() in functions.php).</p><p><a href="https://github.com/WordPress/WordPress/blob/master/wp-includes/template-loader.php">template-loader.php</a> is then called (from wp-load.php). This file decides which template is loaded.</p><p>The first thing it does, is to give you a hook: <a href="https://codex.wordpress.org/Plugin_API/Action_Reference/template_redirect">template_redirect</a>. If you know (based on the data that is loaded) that you will require an alternative template than what would normally be loaded, this is your hook. An example could be a restricted page that loads a login form if the current user is not logged in.</p><p>Next, WordPress checks if the current request is a <a href="https://ochronus.com/http-head-request-good-uses/">http head request</a>. These are used to just get the http header (for instance, to check if a certain page exists, has changed,…). If such a request is detected, the rest of the page is not rendered. If you get a lot of these requests, this can save you a bit of server bandwidth.</p><p>template-loader.php then checks for 3 special cases: robots (Googlebot indexing your page), a page being read as an RSS-feed or a trackback. If any of these are found, a normal template file doesn’t need to be loaded.</p><p>If it is not a special case, WordPress goes through a list of possible templates. Every line first checks if a condition is met (is_404(), is_search(),…). If the condition is met, it checks if the corresponding template exists in the current theme. If it finds a match, that value is saved in the $template variable.</p><p>If none of the special templates need to be loaded (or are available), the default index template is saved into the variable.</p><p>You get a last filter (<a href="https://codex.wordpress.org/Plugin_API/Filter_Reference/template_include">template_include</a>) before it is finally included and you finally see a result in the browser.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e077c7dbd119" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>