0

So I have a website www.chatexplore.com All of my new users are Editors who can upload images and post.

But I dont want edit button at the bottom of the page to be visible to any users except administrators.

I tried my users to add/upload media, only editors can do it. So all of my users are editors. So I just want only administrator to see this button.

2 Answers 2

1

You should not make users editors if you do not want them to be able to edit any content. IIRC an author role is enough to be able to upload images, and that should probably solve your issue. Otherwise if you need something additional to what authors can do, use a plugin that lets you manipulate user and role permissions (or ask a more specific and detailed question ;) )

-2

Try wrapping the button in a PHP if statement that checks if the current user has administrator privelages, like this:

<?php if ( current_user_can( 'administrator' ) ) : ?>

    <a href="#">Your Button</a>

<?php endif; ?>

This Wordpress Codex link explains how to check for administrator privileges.

Also, for a 1-liner this is the same thing:

<?php if ( current_user_can( 'administrator' ) ) { echo '<a href="#">Button</a>'; } ?>

DO NOT USE is_admin() for this as stated here. That function checks if you're in the dashboard, not for the privelages you are looking for.

3
  • 1
    Are you sure you want to use is_admin function? It checks if your in dashboard and not if current user is admin... Commented May 7, 2018 at 5:10
  • @KrzysiekDróżdż You're right! I updated my answer, and Wordpress Codex link. Commented May 7, 2018 at 5:21
  • 2
    First paragraph in linked article says clearly that you SHOULD NOT use current_user_can with roles... Commented May 7, 2018 at 5:25

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.