更改插件名称下的操作链接的布局

时间:2018-08-13 作者:Iurie

一些插件在插件页面上的名称下放置各种链接。要在下面的单独一行中显示特定插件的每个操作链接thisthis 答案,但我的代码不起作用。我做错了什么?

我将WordPress 4.9.8用于儿童2017主题。

add_action( \'admin_enqueue_scripts\', \'wpse_239302_hide_action_links\' );
function wpse_239302_hide_action_links() {
    global $pagenow; 
    if ( $pagenow == \'plugins.php\' ) {
        ?>
        <style type="text/css">
            tr.active[data-slug="super-socializer"] .row-actions.visible span .1,
            tr.active[data-slug="super-socializer"] .row-actions.visible span .2  { display: block; }
        </style>
        <?php
    }
}

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

通过使用以下两个功能将讨论中的链接从插件管理页面的第一列移到第二列,我找到了一个更好的解决方案:

/** Remove action links from the Super Socializer plugin first column **/
const PLUGIN_SLUG = "super-socializer/super_socializer.php";
add_filter("plugin_action_links_" . PLUGIN_SLUG, function ($actions, $plugin_file, $plugin_data, $context) {

    unset($actions[1]); // remove link "Add-Ons"
    unset($actions[2]); // remove link "Support Documentation"

    return $actions;

}, 10, 4);

/** Add action links to the Super Socializer plugin second column **/
add_filter( \'plugin_row_meta\', \'custom_plugin_row_meta\', 10, 2 );
function custom_plugin_row_meta( $links, $file ) {

    if( strpos( $file, \'super_socializer.php\' ) !== false ) {
        $new_links = array(
            \'addons\'    => \'<a href="\' . esc_url( \'https://www.heateor.com/add-ons\' ) . \'" target="_blank" aria-label="\' . 
                esc_attr__( \'Add-Ons\', \'domain\' ) . \'">\' . esc_html__( \'Add-Ons\', \'domain\' ) . \'</a>\', // add link "Add-Ons"
            \'support\'   => \'<a href="\' . esc_url( \'https://www.heateor.com/add-ons\' ) . \'" target="_blank" aria-label="\' . 
                esc_attr__( \'Support Documentation\', \'domain\' ) . \'">\' . esc_html__( \'Support Documentation\', \'domain\' ) . \'</a>\' // add link "Support Documentation"
        );

        $links = array_merge( $links, $new_links );
    }

    return $links;
}

SO网友:Kaperto

您可以使用此筛选器自定义这些链接:
https://developer.wordpress.org/reference/hooks/plugin_action_links_plugin_file/

试试看:

const PLUGIN_SLUG = "super-socializer/super_socializer.php";


add_filter("plugin_action_links_" . PLUGIN_SLUG, function (array $actions, string $plugin_file, array $plugin_data, string $context) {

    unset($actions[1]); // remove link "Add-Ons"
    unset($actions[2]); // remove link "Support Documentation"

    return $actions;

}, 10, 4);

结束