[wp-hackers] Restrict plugin load to certain pages?

David Anderson david at wordshell.net
Mon Jul 1 09:02:35 UTC 2013


Hi,

I am running a plugin which, like many, loads plenty of code on 
irrelevant pages. This one, when profiled in P3 Performance Profiler, 
accounts for 0.27 seconds of page load time on pages which it has 
nothing to do with (its a forum plugin).

I'm confident that there will be no bad side-effects from simply not 
loading this plugin on irrelevant pages (e.g. those without /forum/ in 
the URL). Rather than re-writing the plugin, and then doing it again on 
every other plugin I find in future with this problem, I'd like to write 
some code to simply prevent plugin load, depending on the URL.

Looking at the WP core code, my only option to achieve this seems to be 
to be (via an mu-plugin, since a plugin would present a Catch-22) to 
hook get_option, detect the option 'active_plugins', and remove the 
offending plugin depending on the contents of _SERVER['REQUEST_URI'] and 
is_admin() (I don't want to disable anything admin-side).

Questions...
- Anyone see any problem with this idea?
- Anyone done it already and got some code?
- If plugins loaded in a controllable, deterministic order (e.g. 
deterministic), and with an action added in 
wp_get_active_and_valid_plugins, it would be possible to code this as a 
plugin. Do any of the insiders on this list have an opinion upon whether 
if I submitted a patch for WordPress core to do this it'd have any 
chance of getting in?

Many thanks,
David


-- 
WordShell - WordPress fast from the CLI - www.wordshell.net



More information about the wp-hackers mailing list