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_plugin_file action
The dynamic portion of the hook name, $plugin_file
, refers to the path to the plugin file, relative to the plugins directory.
To use plugin_action_links_plugin_file
action, first you have to register it using add_action
. You can write this code into 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_execute_on_plugin_action_links_plugin_file_event
which takes 4 parameters and we registered using add_action
. The first parameter plugin_action_links_plugin_file
is the name of the hook, The second parameter weplugins_execute_on_plugin_action_links_plugin_file_event
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_action
to remove plugin_action_links_plugin_file
action.
Parameters
- $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’.
Below are the 4 parameters required to use this hook.
Live Example 1
Below is an example of how you can use this hook to add custom action links to a plugin.
add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), 'weplugins_add_action_links' ); function weplugins_add_action_links ( $actions ) { $mylinks = array( '<a href="' . admin_url( 'options-general.php?page=myplugin' ) . '">Settings</a>', ); $actions = array_merge( $actions, $mylinks ); return $actions; }
Live Example 2
Here’s an example of using the hook to execute a custom function.
function weplugins_execute_on_plugin_action_links_plugin_file_event($actions, $plugin_file, $plugin_data, $context){ // You can write code here to be executed when this action occurs in WordPress. } // Add the action add_action( "plugin_action_links_plugin_file", "weplugins_execute_on_plugin_action_links_plugin_file_event" , 10, 4);
Live Example 3
To remove a hook callback, use the example below.
remove_action( "plugin_action_links_plugin_file", "weplugins_execute_on_plugin_action_links_plugin_file_event", 10, 4 );
Please 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, feel free to contact us.
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.