apply_filters( “plugin_action_links_{$plugin_file}”, string[] $actions, string $plugin_file, array $plugin_data, string $context )

Filters the list of action links displayed for a specific plugin in the Plugins list table.

Description

The dynamic portion of the hook name, $plugin_file, refers to the path to the plugin file, relative to the plugins directory.

Parameters

$actionsstring[]
An array of plugin action links. By default this can include 'activate', 'deactivate', and 'delete'. With Multisite active this can also include 'network_active' and 'network_only' items.
$plugin_filestring
Path to the plugin file relative to the plugins directory.
$plugin_dataarray
An array of plugin data. See get_plugin_data() and the 'plugin_row_meta' filter for the list of possible values.
$contextstring
The plugin context. By default this can include 'all', 'active', 'inactive', 'recently_activated', 'upgrade', 'mustuse', 'dropins', and 'search'.

More Information

Applied to the list of links to display on the plugins page (beside the activate/deactivate links).

Basic Example:

add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), 'add_action_links' );

function add_action_links ( $actions ) {
$mylinks = array(
'<a href="' . admin_url( 'options-general.php?page=myplugin' ) . '">Settings</a>',
);
$actions = array_merge( $actions, $mylinks );
return $actions;
}

When the ‘plugin_action_links_(plugin file name)’ filter is called, it is passed one parameter: the links to show on the plugins overview page in an array.

The (plugin file name) placeholder stands for the plugin name that you can normally get from the magic constant __FILE__.

add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), 'my_plugin_action_links' );

function my_plugin_action_links( $actions ) {
$actions[] = '<a href="'. esc_url( get_admin_url(null, 'options-general.php?page=gpaisr') ) .'">Settings</a>';
$actions[] = '<a href="http://wp-buddy.com" target="_blank">More plugins by WP-Buddy</a>';
return $actions;
}

Will result in something like this:
Example 2 Result

We can also edit the link to put them in front of the deactivate and edit link. Here is an example:

add_filter( 'plugin_action_links', 'ttt_wpmdr_add_action_plugin', 10, 5 );

function ttt_wpmdr_add_action_plugin( $actions, $plugin_file )
{
static $plugin;

if (!isset($plugin))
$plugin = plugin_basename(__FILE__);
if ($plugin == $plugin_file) {

$settings = array('settings' => '<a href="options-general.php#redirecthere">' . __('Settings', 'General') . '</a>');
$site_link = array('support' => '<a href="http://thetechterminus.com" target="_blank">Support</a>');

$actions = array_merge($settings, $actions);
$actions = array_merge($site_link, $actions);
}

return $actions;
}

This will work with both single file plugin and a folder plugin:
Example 3 Result

Source

$actions = apply_filters( "plugin_action_links_{$plugin_file}", $actions, $plugin_file, $plugin_data, $context );

Changelog

VersionDescription
4.9.0The 'Edit' link was removed from the list of action links.
2.7.0Introduced.

User Contributed Notes

  1. Skip to note 4 content
    // Link to settings page from plugins screen
    add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), 'add_action_links' );
    function add_action_links ( $links ) {
    	$mylinks = array(
    		'<a href="' . admin_url( 'options-general.php?page=mysettings' ) . '">Settings</a>',
    	);
    	return array_merge( $links, $mylinks );
    }
  2. Skip to note 5 content
    $plugin_file = plugin_basename(__FILE__)

    That works great if you add the filter in the main plugin file.

    If not that’s not the case, you need to specify it.

    Let’s say you have the following directory structure:
    wp-content/plugins/wpdocs-plugin/wpdocs-plugin.php

    The $plugin_file then needs to be wpdocs-plugin/wpdocs-plugin.php

  3. Skip to note 6 content

    If you want to add this in class file then take below reference,

    add_filter( 'plugin_action_links_' . $plugin_file_path, array( $this, 'wpdocs_custom_action_link' ) );
    public function wpdocs_custom_action_link( $links ) { 
        // Build URL.
        $url = add_query_arg( 'page', 'custom-settings', get_admin_url() . 'tools.php' );
    
        // Create the link and escape .
        $setting_link = '<a href="' . esc_url( $url ) . '">' . __( 'Custom Settings', 'domain' ) . '</a>';
    
        // Adds the link to the end of the array.
        array_push( $links, $setting_link );
    
        return $links;
    }

You must log in before being able to contribute a note or feedback.