Examining the WordPress Core, Plugin and Theme Update Procedure

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?

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:

  1. The new plugin/theme zip file is downloaded to wp-content/upgrade/
  2. The zip file is uncompressed
  3. The old theme/plugin folder is deleted
  4. The new theme/plugin folder is copied over to its rightful place
  5. 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.

Useful Resources

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.

Self Hosted Plugin Repository

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 – Software Licensing Extension

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.

Automatic Theme/Plugin Update

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.

Updater for Plugins Hosted on GitHub

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.

Jean Galea
Jean Galea
Jean Galea is an investor, entrepreneur, and blogger. He is the founder of WP Mayor, the plugins WP RSS Aggregator and Spotlight, as well as the Mastermind.fm podcast. His personal blog can be found at jeangalea.com.

Consider sharing this post so others can find it:

Share on facebook
Share on twitter
Share on linkedin
Share on reddit
Share on telegram
Share on whatsapp
Share on pocket
Share on email

Join thousands of people receiving real-world, genuine evaluations of WordPress products and services just like this one every week.

Our Sponsors
Prevent Direct Access
Contents

4 Responses

  1. Thanks! You give us the courage to explore some coding stuff we dare not to touch before in some of our clients’ blogs. Thanks again and have a nice day !!

  2. I’ve been recently looking at this as well, as I had to create my own plugin upgrade feature with code protection. I always find out the most about something when I try to replicate it 🙂

    Nice post, has a lot of good info in it. Hopefully this will encourage more people to have a look and see whats going on.

    Sam

Leave a Reply

Your email address will not be published. Required fields are marked *

The Beginner’s Handbook
From an introduction on how WordPress works to our recommendations on products and services.
👋 Hey there! We're Gaby and Mark
Every week we share tutorials and genuine reviews of WordPress products and services in our newsletter.
Thousands of people read it!
We’d love for you to join.
We’d love for you to join. Here’s what you’ll be getting:

A single weekly email directly to your inbox.