• Hi,
    I am developing a plugin (first time) and want to add role visibility restrictions.

    E.g. I have an number of items that should only be visible to the admin role and a number that should be visible to everyone.

    How do I add the Role Visibility Restrictions?

    If you can point me to documentation that would be great.

    Pat

Viewing 1 replies (of 1 total)
  • See the following Codex entry.
    http://codex.wordpress.org/Roles_and_Capabilities

    You may find some useful information on the links toward the bottom of the page.

    What you essentially need to do is check against a capability a given role has(or doesn’t have)….

    Example:

    <?php
    if( current_user_can( 'manage_options' ) ) :
    // http://codex.wordpress.org/Function_Reference/current_user_can
    
    // Do something only an admin will see
    
    endif;
    
    if( current_user_can( 'read' ) ) :
    // Or alternatively use if( is_user_logged_in() ) :
    // http://codex.wordpress.org/Function_Reference/is_user_logged_in
    
    // Do something any logged in user can see
    
    endif;
    ?>

    Hope that helps..

Viewing 1 replies (of 1 total)
  • The topic ‘Role Visibility Restrictions’ is closed to new replies.