Exciting News! Flipper Code is now WePlugins! Same commitment to excellence, brand new identity.

How to use plugin_action_links_plugin_file action in WordPress

Sandeep Kumar Mishra
Sandeep Kumar Mishra
August 17, 2022
5 minutes read

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

    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 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.

Access Premium WordPress Plugins

Contact Us

If you need any customization, feel free to contact us.

Sandeep Kumar Mishra

Sandeep Kumar Mishra

Sandeep Kumar Mishra writes about WordPress and Artificial Intelligence, offering tips and guides to help you master your website and stay updated with the latest tech trends.

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.