WordPress – How to temporarily disable any plugin per user/page/context

November 10, 2016 | PHP, Plugins, Plugins, Time Savers, Tutorials, Wordpress | 0 comments

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.


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

A Donate Button!


Submit a Comment

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

CommentLuv badge

Stay in touch!

Page Builder Cloud

Page Builder Cloud

A truly universal template library for WordPress Page Builders.

Page Builder Recommendation

Elementor Banner

We are BIG fans of the Elementor page builder. Give it a look!

About this site and Sean Barton

Picture of Sean
Sean Barton is a Freelance PHP Website Developer in Crewe, Cheshire. He is a Wordpress and CMS/Framework specialist and Co-Founder of Page Builder Cloud.
This site was set up in 2008 as a tutorial and scripting resource for the PHP language and Wordpress.
Find out more about Sean on the About Me page or use the Hire Me page to get in touch. For more information about Sean's work take a look at the Portfolio

Our Services

  • Wordpress plugin/theme development
  • Divi specialist
  • Ecommerce (Woocommerce, WPSC, Shopify, Magento)
  • PSD to Wordpress theme conversion (Responsive)
  • Website design work (Banners, Logos, Full Site, etc)
  • Website analysis (security, usability, SEO)
  • API Integrations (InfusionSoft, SalesForce, Ontraport, Customer Thermometer, etc..)
  • Wordpress consultancy & expert advice
  • Crisis support
  • Website hosting

The main services offered are Wordpress based although we do a great deal of technical programming for bespoke systems. From troubleshooting, extending frameworks, finding bugs to writing them from scratch.

Find out more by looking through our past projects or get a quote.

Be the first to hear about new products/updates!

This is a mailing list for those people interested in being told when we release a new product (Divi plugin or Theme).

We shall also use this list to let you know about product updates and releases.

You have Successfully Subscribed!