WordPress.org

Ready to get started?Download WordPress

Forums

Groups
[resolved] Is there a PHP function like get_user_group()? (3 posts)

  1. rthakrar
    Member
    Posted 2 years ago #

    Hi,

    I'd like to create some if statements based on user groups, so was looking for a function like get_user_group() to give me a variable to work with. Is there a function I can use?

    Thanks,

    R

    http://wordpress.org/extend/plugins/groups/

  2. itthinx
    Member
    Plugin Author

    Posted 1 year ago #

  3. rthakrar
    Member
    Posted 1 year ago #

    Thanks, @itthinx.

    I'm not very good with PHP objects, so went for the 'long but simple' route.

    $userid = $current_user->ID;
    
    $user = new Groups_User( $userid );
    $groups = $user->__get( 'groups' );
    
    $gr1 = (get_object_vars($groups[1]));
    $gr2 = (get_object_vars($gr1[group]));
    
    if ($gr2 != "Team members" && $gr2 != "Associates")
    {
    	wp_die('This function is only for Team members and Associates.  Would you like to <a href="'.wp_logout_url( $redirect ).'">log in as another user</a>?');
    }

    Thanks again,

    R

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.