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?
Table of Contents

Sponsored Ad

If you purchase through a link on our site, we may earn a commission.

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 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.

Sponsored Ad

If you purchase through a link on our site, we may earn a commission.

All suggestions are anonymous.

More from our blog...

4 Responses

  1. 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

    1. Glad you found it useful Sam, it’s very interesting to see what goes on behind the scenes.

  2. 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 !!

Post a Comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Stay updated with WP Mayor's newsletter showcase every week

Stay on top of every new WordPress innovation and latest launches. Receive all our fresh product reviews and expert guides directly in your inbox.

Hosting Survey 2024

Are you happy with your hosting provider or are you over-paying for too little? Have your say below!

"*" indicates required fields

What's the main reason you picked this host?*
How happy are you with your host?*

OPTIONAL: If you'd like to receive the results of this survey, please enter your details below.