1

I am trying to introduce controls to users and promote users with elevated rights to monitor the users (which is still done my me, as the site admin) This is because the task is a bit comprehensive with the increasing users for the site.

I know I can hide an entire page using a function, as described here, or by using a plugin. But what I want to achieve specifically is to give a selected few users (hereinafter referred to as "managers"), the ability to add/edit other users of the site. But the personal options in user-edit.php must not be touched by managers.

Currently I have given access to managers for that page and I use an if function to see if logged in user is an admin and display personal options only then.

I understand that the core files shall not be edited as the changes would be removed once an update is installed. Is there a function or some other way, (preferably a non-plugin solution) to achieve the above?

1 Answer 1

0

I'm not sure what exactly you are trying to do, since the link you provided does not speak of removing any admin page (merely excluding some posts).

Anyhow, if you want to block the managers access to some page, you can redirect them to somewhere else if they try to access that page.

add_filter( 'admin_init', 'redirect_managers' );
function redirect_managers() {
    global $pagenow; // Global containing the current page
    if ( $pagenow=='edit.php' && current_user_can('manager') ) {
        // If the user has the manager role, redirect them back to dashboard
        wp_safe_redirect( admin_url() );
        // You can also remove the page from the menu
        remove_submenu_page( 'profile.php' );
    }
}

But if you meant to hide an specific part of a page, while showing the other parts (for example, hide the header but show the footer) that's probably not possible due to hard codes admin pages. You might however be able to modify the sections one by one, for example hook into the avatar, username, etc.

TL;DR

You can't. If a part of the admin area does not support a hook or filter, it means that it's hardcoded in the templates. You have to either modify the core ( Not recommended at all ) or create a plugin that does the job for you, and then disable the entire area.

5
  • Thank you Jack! I think you have misunderstood my issue. Use this link to see my requirement. Currently I am using if (current_user_can('administrator')) { } to achieve this. Is there a better and proper way?
    – Sid
    Commented Jul 22, 2017 at 15:40
  • You're welcome! the current_user_can is the proper way to do it, but as you mentioned, the core files should not be edited. And as I noted, you can't remove parts of a template by hooks or filter since the HTML is hard codes inside the file. You might be able to achieve some of it by removing some hooks like admin_color_scheme_picker, but fully removing the HTML is not possible. @Sid
    – Johansson
    Commented Jul 22, 2017 at 19:56
  • Ok. Can you pl add an extract to your answer, so that I can accept it. Maybe give less prominence to your code, so that a future user is not misdirected?
    – Sid
    Commented Jul 24, 2017 at 4:21
  • I've added a "too long; didn't read" to my answer. Please note, accepting the answer is optional. It's mostly to inform the future visitor that the answer solved the issue. If it was useful for you enjoy it. You can also accept it if you "want".
    – Johansson
    Commented Jul 24, 2017 at 4:28
  • 1
    I know. That's what 5 years at Stack Exchange taught me! :) It is awesome to have one for WordPress. Tx again.
    – Sid
    Commented Jul 24, 2017 at 5:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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