Some plugins place various links under their name on the plugins page. To display these each action links for a specific plugin in a seperate line I followed this and this answers, but my code doesn't work. What I did wrong?

I use WordPress 4.9.8 with a child Twenty Seventeen theme.

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
    }
}
  • 1
    Your title says "hide", but your CSS is display: block; not display: none; - why? – kero Aug 13 at 7:34
  • @kero I'm sorry, it's my fault. Now is OK? – Iurie Malai Aug 13 at 7:38
  • Ok, so you want to display something specific (for your own plugin) in that area? Can you show, what you want to display and how it is currently shown? – kero Aug 13 at 7:47
  • @kero I want just what is shown here, for a third party plugin: wordpress.stackexchange.com/a/241071/25187 – Iurie Malai Aug 13 at 8:30

you can customise these links with this filter :
https://developer.wordpress.org/reference/hooks/plugin_action_links_plugin_file/

try that :

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);
  • Thank you! Good solution! P.S. I only removed the 'array', 'string', 'array', 'string' words from the function. – Iurie Malai Aug 13 at 17:29
  • it's type declaration of the parameters secure.php.net/manual/en/… – Kaperto Aug 13 at 17:59
  • Tested again. Something is wrong with these type declarations. I have this error: Catchable fatal error: Argument 2 passed to {closure}() must be an instance of string, string given in /home/.../twentyseventeen-child/functions.php on line 31. Without them is OK. – Iurie Malai Aug 13 at 18:50
up vote 0 down vote accepted

I found a better solution by moving links in discussion from the first column to the second column of plugin admin page with these two functions:

/** 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;
}

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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