Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Is there any way to determine what plugin the plugin_action_links filter is addressing when it processes the filter?

I'm trying to add some actions for each plugin on the /wp-admin/plugins.php page. Code looks as so:

public function _add_plugin_links(){
    $plugins = get_plugins();
    foreach($plugins as $k=>$plugin){
        add_filter( 'plugin_action_links_' . $k, array(&$this, '_plugin_action_links') );
    } // foreach $plugins
}

public function _plugin_action_links( $links ) {
   $plugin = 'test'; // Somehow get plugin name here?
   $links[] = 'Plugin name is: '.$plugin;
   return $links;
}

I am able to append this text to the end of each plugin link list, but cannot determine exactly which plugin I am adding the text to. Adding a global variable from within _add_plugin_links() simply returns the very last plugin that is parsed from the plugins list.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

There are currently four filters and they carry lots of information:

$prefix = $screen->in_admin( 'network' ) ? 'network_admin_' : '';
$actions = apply_filters( $prefix . 'plugin_action_links', array_filter( $actions ), $plugin_file, $plugin_data, $context );
$actions = apply_filters( $prefix . "plugin_action_links_$plugin_file", $actions, $plugin_file, $plugin_data, $context );

This is a var dump of the parameters for Advanced Custom Fields:

Array
(
    [0] => Array
        (
            [activate] => <a href="plugins.php?action=activate&amp;plugin=advanced-custom-fields%2Facf.php&amp;plugin_status=all&amp;paged=1&amp;s&amp;_wpnonce=62d37299ca" title="Activate this plugin for all sites in this network" class="edit">Network Activate</a>
            [edit] => <a href="plugin-editor.php?file=advanced-custom-fields/acf.php" title="Open this file in the Plugin Editor" class="edit">Edit</a>
            [delete] => <a href="plugins.php?action=delete-selected&amp;checked%5B0%5D=advanced-custom-fields%2Facf.php&amp;plugin_status=all&amp;paged=1&amp;s&amp;_wpnonce=b7f1cf2b36" title="Delete this plugin" class="delete">Delete</a>
        )
    [1] => advanced-custom-fields/acf.php
    [2] => Array
        (
            [Name] => Advanced Custom Fields
            [PluginURI] => http://www.advancedcustomfields.com/
            [Version] => 4.2.2
            [Description] => Fully customise WordPress edit screens with powerful fields. Boasting a professional interface and a powerfull API, it’s a must have for any web developer working with WordPress. Field types include: Wysiwyg, text, textarea, image, file, select, checkbox, page link, post object, date picker, color picker, repeater, flexible content, gallery and more!
            [Author] => Elliot Condon
            [AuthorURI] => http://www.elliotcondon.com/
            [TextDomain] => 
            [DomainPath] => 
            [Network] => 
            [Title] => Advanced Custom Fields
            [AuthorName] => Elliot Condon
        )
    [3] => all
)

You could use the bare plugin_actions_link and detect the plugin file, but it's easier with the second. Example adding an Action Link to ACF in wp-admin/network/plugins.php:

add_filter( 'network_admin_plugin_action_links_advanced-custom-fields/acf.php', function( $actions, $plugin_file, $plugin_data, $context )
{
    $actions['hello'] = 'Hello worlds!';
    return $actions;
}, 10, 4 );

Another filter of interest: plugin_row_meta.

share|improve this answer
    
Great info! I glazed over this part of class-wp-plugins-list-table.php earlier today, thanks :) –  npc Sep 27 '13 at 3:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.