Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

Without a plugin something like this should work

    //functions.php
    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.

share|improve this answer
add comment

This post is a couple years old, but I thought I'd provide a simpler, cleaner conditional that works as of WP 3.5.2

if (current_user_can('subscriber')) {

// subscriber code

} else {

// non-subscriber code

}
share|improve this answer
    
Please explain "as of WP 3.5.2"? What is new about current_user_can? –  s_ha_dum Jul 3 '13 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 '13 at 16:03
    
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 '13 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 '13 at 20:08
    
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 '13 at 22:52
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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