I have been VERY busy of late building the new elegant marketplace (EMP) website and so my blogging and product release schedule has been on hold. As part of getting EMP live though I’ve managed to update a lot of my products (bug fixes and minor improvements really) and will be releasing them again very soon.

On going live we found that a couple of third party plugins (not mine!) were causing extremely high amounts of load on the server and some key tasks on the site simply would not function. This caused 504 errors and very slow page loads. We are only using 50 or so plugins which, for an eCommerce site, is actually pretty low. As an example, the sorts of actions we wanted to do were:

  • Save Nav Menu Items
  • Add/Edit posts/pages/CPT
  • Download a purchased file through the store (EDD)
  • Submit/Edit a product on the front end vendor dashboard

These pages ran out of memory or took close to a minute to load which causes a LOT of stress.

Anyway… I established that if certain plugins could be disabled then the load and memory requirement of these pages would be greatly reduced and the pages would not fall over. We could not simply turn off the culprit plugins because they were integral to the site so we were stuck!

The solution was simple really… for a given page url, file name, querystring parameter or literally any other custom condition we would fool WordPress into thinking that the plugin(s) were not active.

WordPress has a call right at the start of the page load to get_option(‘active_plugins’) which returns an array of plugin paths currently active. It then requires the files and initialises them.. thereafter we have very little control over what they do (or at least we have control but tuning each plugin is prohibitive!). Turning them off was the solution.

On running the following code the offending plugin(s) were removed from the plugin list (but NOT re-saved back to the database so they remained generally active). This resulted in page load times of a few seconds which, compared to 30-60 seconds, was a real win.

The key here is that it needs to be run BEFORE the normal WordPress plugins are called from the DB to enable our little mod to augment the list accordingly. Therefore, the best place to add this is to a ‘mu plugin‘ as they get called before anything else..

The following code (included as a file also for convenience) just needs to be uploaded to wp-content/mu-plugins/ and that’s it. You’ll need to use this as a starting point for your own site. For instance the plugins that needed to be turned off on my project are not going to be the same for you. Also the logic to describe where to disable them will need to be changed for each eventuality.

You can run your slow page with ?debug_mode=1 in the url and this will print a list of the plugins you have active in the format they will need to be in the array at the top of the file.

Download

SB Conditional Disable Plugins (MU Plugin) (34 downloads)

A donate button!