从plugin_action_link筛选器中确定插件名称

时间:2013-09-26 作者:emc

有没有办法确定plugin_action_links 筛选器在处理筛选器时正在寻址?

我正在尝试为上的每个插件添加一些操作/wp-admin/plugins.php 页代码如下所示:

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;
}
我可以将此文本附加到每个插件链接列表的末尾,但无法确定要将文本添加到哪个插件。从中添加全局变量_add_plugin_links() 只需返回从插件列表中解析的最后一个插件。

1 个回复
最合适的回答,由SO网友:brasofilo 整理而成

目前有four filters 它们携带了大量信息:

$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 );
这是高级自定义字段参数的var转储:

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
)
你可以用裸体的plugin_actions_link 并检测插件文件,但第二个更容易。在中向ACF添加操作链接的示例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 );
另一个感兴趣的过滤器:plugin_row_meta.

结束

相关推荐

Plugins_url(‘’,__FILE__)!=带有sym链接的WP_plugin_URL

对于我的众多网站之一,plugins/plugin-name 是指向的符号链接universal-install/wp-content/plugins/plugin-name.echo WP_PLUGIN_URL 显示我期望的内容echo plugins_url(); 显示我期望的内容echo plugins_url(\'\',__FILE__) 显示我期望的内容,后跟指向通用插件目录的绝对路径。我有什么办法可以解决吗echo plugins_url(\'\',__FILE__) 仅返回预期结果?