Using WordPress ‘network_admin_plugin_action_links_{$plugin_file}’ PHP filter

The network_admin_plugin_action_links_{$plugin_file} WordPress PHP filter modifies the action links displayed for a specific plugin in the Network Admin Plugins list table. The dynamic portion of the hook name, $plugin_file, refers to the path to the plugin file, relative to the plugins directory.

Usage

add_filter('network_admin_plugin_action_links_' . $plugin_file, 'custom_plugin_action_links', 10, 4);

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

Parameters

  • $actions (string[]): An array of plugin action links. By default, this can include ‘activate’, ‘deactivate’, and ‘delete’.
  • $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. By default, this can include ‘all’, ‘active’, ‘inactive’, ‘recently_activated’, ‘upgrade’, ‘mustuse’, ‘dropins’, and ‘search’.

More information

See WordPress Developer Resources: network_admin_plugin_action_links_{$plugin_file}

Examples

Add a custom action link to the plugin’s action links in the Network Admin Plugins list table.

add_filter('network_admin_plugin_action_links_' . $plugin_file, 'add_custom_action_link', 10, 4);

function add_custom_action_link($actions, $plugin_file, $plugin_data, $context) {
    $actions['custom_link'] = '<a href="https://example.com">Custom Link</a>';
    return $actions;
}

Remove the ‘deactivate’ link from the plugin’s action links in the Network Admin Plugins list table.

add_filter('network_admin_plugin_action_links_' . $plugin_file, 'remove_deactivate_link', 10, 4);

function remove_deactivate_link($actions, $plugin_file, $plugin_data, $context) {
    unset($actions['deactivate']);
    return $actions;
}

Change the ‘delete’ link text in the plugin’s action links in the Network Admin Plugins list table.

add_filter('network_admin_plugin_action_links_' . $plugin_file, 'change_delete_link_text', 10, 4);

function change_delete_link_text($actions, $plugin_file, $plugin_data, $context) {
    $actions['delete'] = str_replace('Delete', 'Remove', $actions['delete']);
    return $actions;
}

Hide all action links for a specific plugin when the plugin context is ‘active’ in the Network Admin Plugins list table.

add_filter('network_admin_plugin_action_links_' . $plugin_file, 'hide_action_links_for_active_context', 10, 4);

function hide_action_links_for_active_context($actions, $plugin_file, $plugin_data, $context) {
    if ($context == 'active') {
        return [];
    }
    return $actions;
}