Home > Software engineering >  Hide plugins for all users except specified admin in WordPress
Hide plugins for all users except specified admin in WordPress

Time:04-08

I am using the code below to hide a list of plugins from admin dashboard.

add_filter('all_plugins', 'hide_plugins');

function hide_plugins($plugins) {
    unset($plugins['code-snippets/code-snippets.php']);
    unset($plugins['e-addons-display/e-addons-display.php']);
    unset($plugins['e-addons-for-elementor/e-addons-for-elementor.php']);
    unset($plugins['e-addons-twig/e-addons-twig.php']);
    return $plugins;
}

Problem is it hides the plugins for all users, I would like it to hide the plugins for all other users including administrator except the admin with blissguy username.

CodePudding user response:

Something like this? Personally, I think that plugins should be hidden per default, and then they're unhidden if you're accessing it. This seems better when the majority of users is not you. But, here goes:

<?php
$current_user = wp_get_current_user();
$current_user->display_name;

if($current_user->display_name !== 'blissguy') {
    add_filter('all_plugins', 'hide_plugins');
}

?>

Ps. This uses the display_name, but you also have user_login and other variables that can be used. I would recommend using your ID.

  • Related