How to Add/Remove Plugin Action Links

How to Add/Remove Plugin Action Links

The Links which are used to Activate, Deactivate, or Delete the plugin are termed Plugin Action Links. Many plugins prefer to add the ‘Setting’ action link, which is the best way to find a direct link for the setting of that plugin.

Add your custom action link using the ‘plugin_action_links‘ filter.

/**
 * Add Settings Action Link
 * @param $actions
 * @param $plugin_file
 * @param $plugin_data
 * @param $context
 *
 * @return mixed
 */
function cl_add_settings_link( $actions, $plugin_file, $plugin_data, $context ){

	$this_plugin = basename(__FILE__);

	if( strpos( $plugin_file, $this_plugin ) ) {
		// add the link to the list of links already available
		array_unshift( $actions, '<a href="admin.php?page=your-plugin-path">Settings</a>' );
	}

	return $actions;
}
add_filter( 'plugin_action_links', 'cl_add_settings_link', 10, 4 );

Add the above function in your plugin’s main file. Replace the URL with your plugin’s configuration path.

The result:

WordPress Plugin Action Links
Added Settings Action Link

How to Remove Plugin Action Links

When there are multiple admins and you don’t want to remove the specific plugin, you can remove the delete action link by simply hooking into the ‘plugin_action_links’ filter.

The following function can be placed in your theme’s function file or in your custom plugin.

/**
 * Remove Delete Plugin Action Link
 * @param $actions
 * @param $plugin_file
 * @param $plugin_data
 * @param $context
 *
 * @return mixed
 */
function disable_plugin_deletion( $actions, $plugin_file, $plugin_data, $context ) {

	// Remove delete action link for plugins
	if ( array_key_exists( 'delete', $actions ) && in_array( $plugin_file, array(
			'akismet/akismet.php',
			'plugin-folder-name/plugin.php'
		) ) )
		unset( $actions['delete'] );

	return $actions;
}
add_filter( 'plugin_action_links', 'disable_plugin_deletion', 10, 4 );

Replace ‘plugin-folder-name/plugin.php’ with the plugin name you want to remove action for.
For Ex. 'plugin-folder-name/plugin.php' => 'akismet/akismet.php'

Join the discussion

Menu