3

Some plugins place various links under their name on the primary column on the plugin page. So we end up with something like:

Home Page | Support Forums | Documentation | Upgrade to Pro Edition | Donate | Settings | Activate | Delete

In an effort to keep just the standard links Settings | Activate | Delete we use in our custom 01_plugin.php the following code:

 global $pagenow; 
    if( $pagenow == 'plugins.php' ) {
    echo '<style type="text/css">
        .visible .proupgrade, 
        .visible .docs, 
        .visible .forum, 
        .visible .jetpack-home, 
        .visible .support 
            {display: none ; 
            } 
          </style>'; 
    }

When debugging, for some reason, it gives a PHP Warning:

PHP Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /wp-content/plugins/01-plugin/01_plugin.php:282) in /wp-content/plugins/wp-miniaudioplayer/miniAudioPlayer.php on line 231

Can someone point us to the right direction? Which hook should we use?
Is there another way to achieve our goal?

EDIT

To better understand where these links are located, please have a look at the screenshot:

primary-bloated

As you can see they bloat the primary column out of proportion, using/wasting precious space, that could be otherwise awarded to the secondary column.
Note: The primary column does not wrap. The secondary does.

  • 3
    Are you using a hook? – ngearing Sep 14 '16 at 23:49
  • @Nath. No. Not really. The above code is all that is added. Have you any suggestions/answers? – marikamitsos Sep 16 '16 at 13:31
  • So if your not using a hook how are you adding this code? – ngearing Sep 19 '16 at 23:19
  • I cannot figure out where to hook it. Could you provide a solution? Even better could one use a non-css solution? – marikamitsos Sep 28 '16 at 21:41
  • Check out codex.wordpress.org/Plugin_API/Action_Reference/… to add your own css. I can't really provide better than that at the moment as I am still not sure what you are trying to do really. – ngearing Sep 28 '16 at 23:17
3

You have the right approach. You will want to use the admin_enqueue_scripts hook:

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">
            .visible .proupgrade,
            .visible .docs,
            .visible .forum,
            .visible .jetpack-home,
            .visible .support { display: none; } 
        </style>
        <?php
    }
}
  • Worked like a charm. Two newbie questions though. 1. Is this what we should do whenever targeting admin pages using css (create a new action with a custom function and use admin_enqueue_scripts)? 2. Let's say we need to target other admin screens e.g. for the profile screen .user-admin-color-wrap to hide the Admin color Scheme as well as for the dashboard use ` #wp-version-message` to hide the wordpress version for just the subscribers. Do we need to create a new action for every single screen? Can we combine them and how? Could you please update your answer with the relevant code? – marikamitsos Sep 29 '16 at 21:30
  • @marikamitsos To answer your first question, it depends. Also, it's best to ask a separate question since the original question have been solved. This way, I can give you a better and more detailed answer, with an example. – Ethan Jinks O'Sullivan Sep 30 '16 at 0:29
  • I was afraid this would be the reply for my second question. But I thought of giving it a shot anyway. You could elaborate though on the "depends" part, since 'providing additional context regarding how and/or why it solves the problem would improve the answer's long-term value". – marikamitsos Sep 30 '16 at 2:36
  • @marikamitsos Again, it depends because I rather show you a couple of answers in order to achieve the same results with more details in my reasoning. Unfortunately the amount of characters I can type in these comments won't be enough or legible. – Ethan Jinks O'Sullivan Sep 30 '16 at 2:45
  • Of course "the amount of characters I can type in these comments won't be enough or legible". It is not what I suggest here. On the other hand it is quite common for someone to edit an answer in order to provide a really useful reply. – marikamitsos Sep 30 '16 at 3:04
1

you can use this:

add_action('admin_footer', function () {
    if( $GLOBALS['pagenow'] == 'plugins.php' ) {
    echo '<style type="text/css">.visible .proupgrade,  .visible .docs, .visible .forum, .visible .jetpack-home, .visible .support {display: none ; }   </style>'; 
    }
});

to style admin dashboard for different roles, then you have to append user-role into body-class (Use this) .

  • Your code works great as well. Could you please explain though couple of points? Why should one use admin_footer and not admin_enqueue_scripts? Is it because it is css which should/could be loading in the footer? Are there any differences/benefits or just personal preference? Since it is just a line would it make any difference inlining it and if so how? Do you also have an opinion concerning my comment on the other answer? – marikamitsos Sep 29 '16 at 22:47
  • it is just personal preference and easier to hook into admin_footer, however, for scripts and styles, more recommended way is admin_enqueue_scripts (but that is used primarily for major scripts and styles, like jquery,bootstrap and etc), in your case, the custom solution i have given, will work well too. I will make another answer for the other question you wanted for subscribers and etc.. – T.Todua Sep 30 '16 at 5:48
  • I've commented you there too, about user-roles. – T.Todua Sep 30 '16 at 5:57
  • Thank you for the detailed explanation. Could you please edit your answer and incorporate it so others can benefit as well. – marikamitsos Sep 30 '16 at 6:10
  • @marikamitsos ok, done. – T.Todua Sep 30 '16 at 6:17
0

We might also try to change the layout via CSS, differently than hiding it.

Here's an example where we target the row actions of that plugin and display each action in a seperate line:

tr.active[data-slug="all-in-one-seo-pack"] .row-actions.visible span{
    display: block;
}

Note that we target only the action rows when the plugin is active:

active

else it's like this:

deactive

  • Sorry. As you can see from the original post I refer to .visible .jetpack-home, .visible .support as well. "All In One SEO Pack" just happens to be in the example screenshot. As for the "tried to remove the settings action link via the plugin_action_links filter, but that didn't work" part I had looked into that and I think it is because there is no named span class given to it, but only a number 0 or 1 hijacking the positions. Other plugins do that as well. So ideally one should not target (if possible) the name (Upgrade to Pro) and not the class (proupgrade) – marikamitsos Sep 30 '16 at 12:43
  • Your second update is very interesting! So interesting, I don't understand why is it not included in the core for the whole plugins page. – marikamitsos Sep 30 '16 at 12:45
  • In general we should avoid removing those extra links (I therefore removed that part from my answer), because we never know when we need them and theycan be important for that plugin ;-) Yes I agree with you that, this is a bug that should be fixed. You should consider filing a ticket, if no-one has reported this before. @marikamitsos – birgire Sep 30 '16 at 12:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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