I am having private page.I want to show this page only when "subscriber" logged in."Editor" should not access this page.How can i set the privilege.

2 Answers 2


Without a plugin something like this should work

    function get_user_role() {
    global $current_user;

    $user_roles = $current_user->roles;
    $user_role = array_shift($user_roles);

    return $user_role;

    //page template
    $role = get_user_role();
    if($role == "subscriber"){
       //cool you can see this
    else {
       //sorry not allowed

A BETTER way would be to use something like the Members Plugins which lets you have custom roles and check roles and such.


This post is a couple years old, but I thought I'd provide a simpler, cleaner conditional:

if (current_user_can('subscriber')) {

// subscriber code

} else {

// non-subscriber code

  • Please explain "as of WP 3.5.2"? What is new about current_user_can?
    – s_ha_dum
    Jul 3, 2013 at 19:22
  • As of v3.5.2, which is the version I'm currently using when I posted my answer, this conditional answers the OP question in a much cleaner/simpler way than the accepted answer. How is that not clear?
    – Spartacus
    Jul 16, 2013 at 16:03
  • 1
    current_user_can is not new in 3.5.2. It has been around since 2.0.0, according to a note in the source. Your answer implies that this works beginning with -- aka, "as of"-- WordPress 3.5.2. That is not accurate.
    – s_ha_dum
    Jul 16, 2013 at 16:13
  • 1
    "As of" does not imply beginning with... Please don't argue with me about semantics of the English language. Nor did I say current_user_can is a new function. Please also stop arguing with me about the intent of my answer.
    – Spartacus
    Jul 22, 2013 at 20:08
  • 2
    I am not arguing about the intent of your answer but I found the language of your answer to be confusing, so I asked a question, then, as you didn't understand the confusion, I explained why. Simple process. Not really something worth the hostility.
    – s_ha_dum
    Jul 22, 2013 at 22:52

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.