A few weeks ago I got curious to examine exactly how WordPress Core, plugins and themes are update. You know the drill from a user point of view. You get the update notification in your admin, you click update and everything is updated painlessly (usually). But what exactly is happening behind the scenes?
Well, here’s what happens in a nutshell.
Let’s start with themes and plugins. Here I am referring to themes and plugins downloaded from the WordPress.org repository. When you hit the update link, what happens is the following:
- The new plugin/theme zip file is downloaded to wp-content/upgrade/
- The zip file is uncompressed
- The old theme/plugin folder is deleted
- The new theme/plugin folder is copied over to its rightful place
- The theme/plugin is activated once again.
It’s quite a straightforward process really.
The WordPress Core update process is actually slightly different. Since the Core is a more sensitive part of your site, more care is taken here.
The file we need to look at is update-core.php, found in the wp-admin/includes/ directory.
In a testament to how well-commented WordPress is, I’m just going to go ahead and almost paste the comments from the update_core() function unedited, and I’m sure you will understand the WordPress Core update process without any need for further explanation:
Note: The .maintenance file referred to below sits at the base of the WordPress directory to ensure that people can not access the web site, when the files are being copied to their locations.
The files in the $_old_files list will be removed and the new files copied from the zip file after the database is upgraded.
The files in the $_new_bundled_files list will be added to the installation if the version is greater than or equal to the old version being upgraded.
The steps for the upgrader for after the new release is downloaded and unzipped is:
1. Test unzipped location for select files to ensure that unzipped worked.
2. Create the .maintenance file in current WordPress base.
3. Copy new WordPress directory over old WordPress files.
4. Upgrade WordPress to new version.
4.1. Copy all files/folders other than wp-content
4.2. Copy any language files to WP_LANG_DIR (which may differ from WP_CONTENT_DIR
4.3. Copy any new bundled themes/plugins to their respective locations
5. Delete new WordPress directory path.
6. Delete .maintenance file.
7. Remove old files.
8. Delete ‘update_core’ option.
There are several areas of failure. For instance if PHP times out before step 6, then you will not be able to access any portion of your site. Also, since the upgrade will not continue where it left off, you will not be able to automatically remove old files and remove the ‘update_core’ option. This isn’t that bad.
If the copy of the new WordPress over the old fails, then the worse is that the new WordPress directory will remain.
If it is assumed that every file will be copied over, including plugins and themes, then if you edit the default theme, you should rename it, so that your changes remain.
Excellent explanation right? I’ll be the first to admit that in the past I’ve been somewhat apprehensive at the thought of opening WordPress core code and just reading through it.
However, as I delved further into plugin development, the WordPress Core became an essential source of knowledge for me. If you’ve never looked at WordPress core code, I encourage you to start today and take a look at some files. You’re not going to read through it like a book, but day by day you will become more familiar with the internals of WordPress, and that is the only way to really become knowledgeable about how WordPress works.
Also, if you’d like to learn how to do a WordPress manual update, here’s the link you need.
For those of you who would like to delve deeper into the subject, and maybe implement their own update procedures, here are some good resources.
Code to create your own self-hosted WordPress Plugin repository for pushing automatic updates. You can also read the tutorial on which this code is based.
Easy Digital Downloads is an amazing free plugin for selling digital products (including themes and plugins) from your own website. The Software Licensing add-on module gives you full functionality for providing licenses to your users, and also includes functionality for automatic theme and plugin updates. It’s a complete package that is essential for all those who want to sell their own themes or plugins.
GitHub repository to provide updates for themes and plugins that can’t be submitted to official WordPress repository, ie … commercial themes/plugins/, non-gpl licensed, written for one client. Based on this guide.
This class is meant to be used with your Github hosted WordPress plugins. The purpose of the class is to allow your WordPress plugin to be updated whenever you push out a new version of your plugin; similarly to the experience users know and love with the WordPress.org plugin repository.
If you enjoyed this post, make sure to subscribe to WP Mayor’s RSS feed.