Using WordPress ‘plugin_action_links’ PHP filter

The plugin_action_links WordPress PHP filter modifies the action links displayed for each plugin in the Plugins list table. These links can include ‘activate’, ‘deactivate’, and ‘delete’, or ‘network_active’ and ‘network_only’ for Multisite.

Usage

add_filter('plugin_action_links', 'customize_action_links', 10, 4);

function customize_action_links($actions, $plugin_file, $plugin_data, $context) {
    // your custom code here
    return $actions;
}

Parameters

  • $actions (string[]): An array of plugin action links.
  • $plugin_file (string): Path to the plugin file relative to the plugins directory.
  • $plugin_data (array): An array of plugin data. See get_plugin_data() and the ‘plugin_row_meta’ filter for the list of possible values.
  • $context (string): The plugin context. Can include ‘all’, ‘active’, ‘inactive’, ‘recently_activated’, ‘upgrade’, ‘mustuse’, ‘dropins’, and ‘search’.

More information

See WordPress Developer Resources: plugin_action_links

Examples

Add a custom link to the plugin’s settings page:

function customize_action_links($actions, $plugin_file, $plugin_data, $context) {
    $settings_url = admin_url('options-general.php?page=my-plugin-settings');
    $actions['settings'] = '<a href="' . $settings_url . '">Settings</a>';
    return $actions;
}
add_filter('plugin_action_links', 'customize_action_links', 10, 4);

Remove the ‘deactivate’ link for a specific plugin:

function remove_deactivate_link($actions, $plugin_file, $plugin_data, $context) {
    if ($plugin_file === 'my-plugin/my-plugin.php') {
        unset($actions['deactivate']);
    }
    return $actions;
}
add_filter('plugin_action_links', 'remove_deactivate_link', 10, 4);

Change the order of action links for a specific plugin:

function reorder_action_links($actions, $plugin_file, $plugin_data, $context) {
    if ($plugin_file === 'my-plugin/my-plugin.php') {
        $actions = array('settings' => $actions['settings']) + $actions;
    }
    return $actions;
}
add_filter('plugin_action_links', 'reorder_action_links', 10, 4);

Add a link to the plugin’s documentation:

function add_documentation_link($actions, $plugin_file, $plugin_data, $context) {
    $documentation_url = 'https://www.example.com/plugin-documentation';
    $actions['documentation'] = '<a href="' . $documentation_url . '" target="_blank">Documentation</a>';
    return $actions;
}
add_filter('plugin_action_links', 'add_documentation_link', 10, 4);

Display action links based on the plugin’s status:

function conditional_action_links($actions, $plugin_file, $plugin_data, $context) {
    if ($plugin_data['TextDomain'] === 'my-plugin' && $plugin_data['Version'] < '2.0') {
        unset($actions['activate']);
        $actions['upgrade_notice'] = '<span style="color:red;">Upgrade required</span>';
    }
    return $actions;
}
add_filter('plugin_action_links', 'conditional_action_links', 10, 4)