WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] display links to specific user roles (3 posts)

  1. cinemaduro
    Member
    Posted 3 years ago #

    I have created two new roles with basically the same access as subscribers except they can both read private pages. I want to display a list of links in a php widget that is different depending on what role the logged in user is.

    I'm not real hot with PHP code, but could I do something like:

    get role_name
    if role_name is AAAA then (display code)
    if role_name is BBBB then (display code)
    else
    (display default code)

    I have some code that almost does what I want, but it is based on what privledges a role has instead of what the actual role is. Since both new roles have the same privledges, I can't differentiate. Here's that particular code:

    [code]
    <?php
    if ( current_user_can( 'read_private_pages' ) ) { ?>
    Page for Role AAAA

    <?php } else { ?>
    Page for Role BBBB
    <?php } ?>

    <?php } ?>
    [/code]

    Any thoughts? Thanks!

  2. cinemaduro
    Member
    Posted 3 years ago #

    I just found out that apparently you can say use roles with current_user_can and not just privileges. Haven't tested it yet, but going to close the thread for now.

    Example:

    <?php
    if ( current_user_can( 'Editor' ) ) { ?>
    display this code
    
    <?php } else { ?>
    display that code
    <?php } ?>
    <?php } ?>
  3. nyckidd
    Member
    Posted 2 years ago #

    hey i have like 5 user roles how do i show a link if user A from user role A is logged on ?

Topic Closed

This topic has been closed to new replies.

About this Topic