Asking for non plugin code, what’s that all about.

It is very common within the WP community to see someone asking for custom work to be done without a plugin. Often the answer requires custom code but for some reason the users thinks that writing it in a plugin somehow adds to overhead. It’s as if clicking “activate”  somehow incurs an internal slowdown.

A quick glance at WPSE shows 1,341 results for questions tagged “without a plugin”,  many involving complex answers that actually do belong in a plugin. So why are people asking this?

My hunch is many users have had a bad experience with a plugins at some point in time and this leads them to believe that all plugins slow WordPress down. The only other explanation would be the idea somehow WP is so inefficient that merely including extra code turns it into a bowl of molasses. The culprit in reality are the plugins themselves and not WordPress, and the association or experiences that all plugins are somehow adding “overhead” is wrong.

The plugin landscape covers a lot of territory, it’s pretty common to have 10-20 plugins on a site, I have seen sites running over 100 plugins, some of them very feature rich (there are plugins that contain over 250 files!). Many of us have installed plugins that are bloated and poorly coded that in fact do bring WP to it’s knees, it’s important to keep in mind not all plugins are the same.

To begin let’s check out how WordPress loads plugins. Plugins are loaded in WP’s boot process via `wp-settins.php`,  a file which controls most of how WP loads. Plugins are not loaded right away but after several important “bits”:

  1. Initialization constants and functions
  2. Early files , hooks and filters, DB connection
  3. Most of WordPress core files (including mu plugins)
  4. Plugins <–
  5. WP Query and a bunch of core class’s
  6. A bunch of stuff and your theme’s functions.php

For reference the actual code that WP uses to load active plugins can be seen on line 196 of wp-settings.php

// Load active plugins.
foreach ( wp_get_active_and_valid_plugins() as $plugin )
	include_once( $plugin );
unset( $plugin );

For a more in depth overview check out:  (slideshow) or (text)

I won’t get into the specifics of the load order,  it’s important to point out 2 things to beginners.

  1. Loading code from a plugin or theme makes no difference performance wise.
  2. WordPress does not load inactive plugins.

But that does not cover everything, it’s important to discuss another factor that effects your site, the #amount of plugins. It’s common sense that as you add more plugins more processing will be needed.. Plugins (and themes ) are not coded with air, they need to actually do things, things which  require ram… but….

You can easily accommodate hundreds(thousands) of well coded plugins on a server, but one badly coded plugin can cripple even the best.

Let’s have a look at 2  random plugins and see what’s going on in terms of performance:

  • Akismet  –  Front-end —  Memory 0.1MB  /  Time 0.004
  • bbPress –  Front-end —   Memory 3.8MB  /   Time 0.061

As you can see from this poor example not all plugins are the same (stats taken from /2011). It would be better to actually test your current plugins which can be done with the plugin profiler:

Poorly coded themes, plugins or anything for that matter, even operating systems (I’m looking at you Windows Vista)  will always lack performance, the connection to assume plugins are somehow inherently “bad” is a misunderstanding.

So enough of the “without a plugin” questions, plugins are a good thing 🙂

It is also important to mention that plugins have many advantages over themes in terms of portable and modular code. Does anyone like a `functions.php` stuffed with thousands of lines of theme specific code that cannot be easily moved to another theme?

I’m pretty sure it’s no one.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s