Using WordPress ‘pre_current_active_plugins’ PHP action

The pre_current_active_plugins WordPress PHP action fires before the plugins list table is rendered, and it also fires before the plugins list table is rendered in the Network Admin. The ‘active’ portion of the hook name does not refer to the current view for active plugins, but rather to all plugins actively-installed.

Usage

add_action('pre_current_active_plugins', 'your_custom_function');
function your_custom_function($plugins_all) {
  // your custom code here
}

Parameters

  • $plugins_all (array): An array of arrays containing information on all installed plugins.

More information

See WordPress Developer Resources: pre_current_active_plugins

Examples

Change plugin names

This example updates the plugin names in the list table.

add_action('pre_current_active_plugins', 'change_plugin_names');
function change_plugin_names($plugins_all) {
  foreach ($plugins_all as &$plugin) {
    $plugin['Name'] = 'Custom - ' . $plugin['Name'];
  }
}

Add a custom message to plugin descriptions

This example adds a custom message to each plugin’s description in the list table.

add_action('pre_current_active_plugins', 'add_custom_message_to_descriptions');
function add_custom_message_to_descriptions($plugins_all) {
  $custom_message = 'This is a custom message.';

  foreach ($plugins_all as &$plugin) {
    $plugin['Description'] .= ' ' . $custom_message;
  }
}

Remove specific plugin from list table

This example removes a specific plugin from the list table based on its folder and file name.

add_action('pre_current_active_plugins', 'remove_specific_plugin');
function remove_specific_plugin(&$plugins_all) {
  $plugin_to_remove = 'plugin-folder/plugin-file.php';

  foreach ($plugins_all as $key => $plugin) {
    if ($plugin['PluginURI'] == $plugin_to_remove) {
      unset($plugins_all[$key]);
      break;
    }
  }
}

Order plugins list table alphabetically

This example orders the plugins list table alphabetically based on their names.

add_action('pre_current_active_plugins', 'order_plugins_alphabetically');
function order_plugins_alphabetically(&$plugins_all) {
  usort($plugins_all, function($a, $b) {
    return strcmp($a['Name'], $b['Name']);
  });
}

Change the version of all plugins

This example changes the version of all plugins to a custom version number.

add_action('pre_current_active_plugins', 'change_plugin_versions');
function change_plugin_versions(&$plugins_all) {
  $custom_version = '1.0.0';

  foreach ($plugins_all as &$plugin) {
    $plugin['Version'] = $custom_version;
  }
}