This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.
plugin_action_links filter
Filters the action links displayed for each plugin in the Plugins list table.
To use the `plugin_action_links` filter, you first have to register it using `add_filter`. You can write this code into the `functions.php` of your activated theme or in a custom WordPress Plugin.
We at WePlugins, always prefer to create a custom WordPress Plugin while using hooks so nothing breaks when you update your WordPress Theme in the future.
In the below live example, we have defined a function `weplugins_modify_plugin_action_links_defaults` which takes 4 parameters and we registered using `add_filter`. The first parameter `plugin_action_links` is the name of the hook, The second parameter `weplugins_modify_plugin_action_links_defaults` is the name of the function which needs to be called, the third parameter is the priority of calling the hook if the same hook is used multiple times and the last parameter is the number of arguments (if any) to be passed in the registered function.
Sometimes, you have to remove a registered hook so you can use `remove_filter` to remove `plugin_action_links` filter.
Parameters
Below are the 4 parameters required to use this hook.
- $actions : (string[]) 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_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’.
Live Example
Add Settings Link to Plugin Actions
This example adds a settings link to the plugin actions.
/** * Add settings link to plugin actions * * @param array $plugin_actions * @param string $plugin_file * @since 1.0 * @return array */ function weplugins_add_plugin_link( $plugin_actions, $plugin_file ) { if ( 'comment-limiter/comment-limiter.php' === $plugin_file ) { $plugin_actions['settings'] = sprintf( '<a href="%s">%s</a>', esc_url( admin_url( 'options-general.php?page=comment-limiter' ) ), __( 'Settings', 'comment-limiter' ) ); } return $plugin_actions; } add_filter( 'plugin_action_links', 'weplugins_add_plugin_link', 10, 2 );
Modify Plugin Action Links
Below is an example of how you can use this hook to modify plugin action links.
function weplugins_modify_plugin_action_links_defaults($actions, $plugin_file, $plugin_data, $context) { // Update the $actions variable according to your website requirements and return this variable. // You can modify the $actions variable conditionally too if you want. return $actions; } // add the filter add_filter( "plugin_action_links", "weplugins_modify_plugin_action_links_defaults", 10, 4 );
Remove a Hook Callback
To remove a hook callback, use the example below.
remove_filter( "plugin_action_links", "weplugins_modify_plugin_action_links_defaults", 10, 4 );
Make sure to provide the same callback function name, priority, and number of arguments while removing the hook callback.
Contact Us
If you need any customization or if you’re having any trouble using this hook, please contact our WordPress Development Team and we’d be happy to assist you.
Explore the latest in WordPress
Trying to stay on top of it all? Get the best tools, resources and inspiration sent to your inbox every Wednesday.