Reduce the Size of Your WordPress Plugin Footprint

For each WordPress plugin you install, you are adding to the bandwidth/server overhead of your site. As a plugin author, there are some simple steps to take to reduce the footprint of your plugin (whether it be helping with server load or conserving bandwidth), even if your plugin still requires a lot of code. Break […]

For each WordPress plugin you install, you are adding to the bandwidth/server overhead of your site. As a plugin author, there are some simple steps to take to reduce the footprint of your plugin (whether it be helping with server load or conserving bandwidth), even if your plugin still requires a lot of code.

Break Out Admin Panels Into Separate Files: Even for simple plugins, adding admin panels can easily balloon a plugin’s file size. A simple, yet effective technique, is to copy the code used for the admin panel to a separate file and simply provide an include in the function that loads the admin panel.

For example, say you load in your admin panel using this code:

add_options_page('Plugin Name', 'Plugin Name', 10, basename(__FILE__), 'printAdminPage');


The function printAdminPage is going to be the function that loads the admin panel. Within this function you could have:

function printAdminPage() {
	include 'includes/admin-panel.php';
}


The above snippet assumes you have an ‘includes’ directory with your admin panel code in ‘admin-panel.php’.

Note: Per Dougal Campbell, includes pose a security risk. Here is one technique for securing PHP include files.

Full Article

WordPress, WordPress Plugin, Plugin Footprint, How To, Tips and Tricks, PHP