WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Role Scoper: Conditional Data Display Functions? (9 posts)

  1. fredhead
    Member
    Posted 3 years ago #

    In RS, I have created groups. In my right column sidebar, I want to display links based on what group the user belongs to.

    What RS function(s) can be used to display content based on group assignment? And, if that's possible, what arguments are passed to the function? Can I also assume the argument is the exact group name as defined in Users > Role Groups?

    I see is_restricted_rs() and users_who_can() are available but it is unclear to me what arguments these functions take and precisely how they function.

    Thanks!

  2. Rhand
    Member
    Posted 3 years ago #

    Did you ever figure this out? I am also looking for this.

  3. fredhead
    Member
    Posted 3 years ago #

    No response yet. However, Kevin was on vacation a week or two ago. I plan to ping him this weekend, to see if he is around. He's conscientious.

    Also, FWIW, this particular topic is mentioned in his documentation as a work in progress.

  4. Rhand
    Member
    Posted 3 years ago #

    Checking out his documentation/forum now. Thanks for the feedback fredhead!

  5. Kevin Behrens
    Member
    Posted 3 years ago #

    What RS function(s) can be used to display content based on group assignment?

    // substitute actual group ID here (id argument in edit links on User > Role Groups)
    $group_id_in_question = 12; 
    
    global $current_user;
    if ( isset( $current_user->groups[ $group_id_in_question ] ) ) {
       // do stuff
    }
  6. Rhand
    Member
    Posted 3 years ago #

    Thanks for that kevinB. Will play with this on a site in progress

  7. fredhead
    Member
    Posted 3 years ago #

    Thanks, Kevin!

  8. Rhand
    Member
    Posted 3 years ago #

    I tried the following in a php widget:

    $group_id_in_question = 9;
    $current_user = wp_get_current_user();
    $user_id = $current_user->ID;
    if ( isset( $current_id->$group_id[ $group_id_in_question ] ) ) echo "www";
    else
    echo "hhh";

    But hhh is shown so if statement does not work.

    // substitute actual group ID here (id argument in edit links on User > Role Groups)
    $group_id_in_question = 9; 
    
    global $current_user;
    if ( isset( $current_user->groups[ $group_id_in_question ] ) ) {
      echo "hhh";
    }

    Seems to work sometimes.... It just does not using the widget logic widget with the same code. Very odd. Will try again tomorrow

  9. Rhand
    Member
    Posted 3 years ago #

    let me correct last statement.

    <?php
    // substitute actual group ID here (id argument in edit links on User > Role Groups)
    $group_id_in_question = 9; 
    
    global $current_user;
    if ( isset( $current_user->groups[ $group_id_in_question ] ) ) {
      echo "hhh";
    else
    echo "Nope";
    }
    ?>

    Does not run either. Only the PHP widget title not part of the if else statement is shown. Neither the if nor the else echo is shown.

Topic Closed

This topic has been closed to new replies.

About this Topic