WordPress Plugin Overhead

I recently wrote an article on why you should bury the bulk of your plugin PHP code at least TWO levels deep from the top-level directory.  The short version: WordPress builds a list of every single PHP file in the plugin directory and first level subdirectories then opens every single one and reads the first 8K scanning for the /* Name: string to build a list of plugins and their meta.  This is triggered by the get_plugins() function in WordPress Core.

More investigation of WP Core 4.7.3 get_plugins and how moving your php files at least 2 levels deep can impact performance is warranted.  Understanding when WordPress is going to run this function will help you determine what the overall performance impact will be and whether or not it is worth modifying your plugins.

My old-school computer background tells me that file opens and string regex comparisons are costly even on today’s fastest solid state drive servers.    The operating system overhead of opening and closing files tends to be costly especially when servers now have millions or billions of file address pointers to  sift through to find the proper memory or disk offsets.  If you are running on one of the millions of old-school spinning magnetic disk servers that are still out there the performance hit will be even more significant.

What Calls get_plugins()

wp-admin

import.php

Import WordPress Administration Screen

Direct load, no function/method.

$plugins = get_plugins( ‘/’ . $plugin_slug );

plugin-editor.php

Edit plugin editor administration panel.

Direct load, no function/method.

$plugins = get_plugins();

plugins.php

If $_REQUEST verify-delete is set.

if ( $folder_plugins = get_plugins( ‘/’ . $plugin_slug ) ) {

wp-admin/includes

ajax-actions.php

Administration API: Core Ajax handlers

function wp_ajax_update_plugin()

Ajax handler for updating a plugin.

$plugin_data = get_plugins( ‘/’ . $result[ $plugin ][‘destination_name’] );

class-language-pack-upgrader.php

Core class used for updating/installing language packs (translations)

public function get_name_for_update

Get the name of an item being updated.

$plugin_data = get_plugins( ‘/’ . $update->slug );

class-plugin-upgrader.php

Upgrade API: Plugin_Upgrader class

public function plugin_info

This isn’t used internally in the class, but is called by the skins.

Needs further investigation.   If I recall this method is widely used.

$plugin = get_plugins(‘/’ . $this->result[‘destination_name’]); //Ensure to pass with leading slash

Called by:
  • class-plugin-installer-skin.php : $plugin_file = $this->upgrader->plugin_info();
  • class-plugin-upgrader-skin.php : $this->plugin = $this->upgrader->plugin_info();
  • class-plugin-upgrader.php:  $this->skin->plugin_info = get_plugin_data( WP_PLUGIN_DIR . ‘/’ . $plugin, false, true);

class-wp-plugins-list-table.php

List Table API: WP_Plugins_List_Table class

public function prepare_items

Undocumented but in WP_List_Table this is what sets the list of items to show.

Looks like this will be called every single time you go to your plugins tab on WP Admin.

$all_plugins = apply_filters( ‘all_plugins’, get_plugins() );

dashboard.php

WordPress Dashboard Widget Administration Screen API

function wp_dashboard_plugins_output

If you have plugins setup on your WP Admin Dashboard and the transient is expired….

$plugin_slugs = array_keys( get_plugins() );

plugin-install.php

WordPress Plugin Install Administration API

function install_plugin_install_status

Determine the status we can perform on a plugin.

If the status is install.   Minimal impact as it only will happen during a plugin install.

$installed_plugin = get_plugins(‘/’ . $api->slug);

plugin.php

WordPress Plugin Administration API

function validate_plugin

Validate the plugin path. Checks that the file exists and is a valid file. See validate_file().

Happens during plugin activation.

$installed_plugins = get_plugins();

Called By
  • plugin.php activate_plugin()
  • plugin.php validate_active_plugins()

update.php

WordPress Administration Update API

function get_plugin_updates

Undocumented

This is likely called from the update plugins routine that runs every 12 hours by default. This runs every time the function is called.

$all_plugins = get_plugins();

Called by
  • update-core.php :list_plugin_updates()
  • class-wp-automatic-updater.php : send_email() when success

wp-includes

update.php

A simple set of functions to check our version 1.0 update service.

function wp_update_plugins

Check plugin versions against the latest versions hosted on WordPress.org.

$plugins = get_plugins();

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.