Resources

My Agape try

Your Agape try


Support Forum

You must be logged in to post Login Register

Search 
Search Forums:


 




check if user has a certain role

UserPost

7:45 am
April 20, 2010


c0d3r

Member

posts 5

1

Sorry for the cross post (http://agapetry.net/forum/revisionary-support/checking-if-user-has-a-certain-role/page-1), but I figured I did not post my question in the right forum in the first place

I am writing a custom php page which will be called from within Wordpress.

I would like to build in some logic to allow certain people to view certain things in the page.

How can I check if a user belongs to a certain role (custom role that is) from within my php code ?

thanks

9:47 pm
April 23, 2010


Kevin

Admin

posts 2503

2

If you're talking about a blog-wide WordPress role:

global $current_user;
if ( ! empty( $current_user->roles['role_name'] ) ) {
   // do stuff
}

You can also test the contents of $current_user->assigned_term_roles['category']['']

2:21 am
April 24, 2010


c0d3r

Member

posts 5

3

Let's say I created a user group called "Test Users" with Role Scoper

How can I test in my php code if a logged on user is member of that group ?


both

$current_user->roles['Test Users']
$current_user->assigned_term_roles['Test Users']['']

don't to work (as they are not really querying user groups I guess)


7:44 am
April 26, 2010


Kevin

Admin

posts 2503

4

c0d3r said:

Let's say I created a user group called "Test Users" with Role Scoper

How can I test in my php code if a logged on user is member of that group ?

both

$current_user->roles['Test Users']
$current_user->assigned_term_roles['Test Users']['']

don't to work (as they are not really querying user groups I guess)




Here's the code:

global $current_user;

$group = ScoperAdminLib::get_group_by_name( "Test Users" );

if ( in_array( $group->ID, $current_user->groups ) ) {
  // do stuff
}

8:25 am
April 26, 2010


c0d3r

Member

posts 5

5

cool, thanks !


2:19 pm
May 3, 2010


nslatter

Member

posts 2

6

How could I pull in a dynamic_sidebar for a specific RoleScoper group?

Not sure if I should start another topic altogether since the question seems to fit within this one.

Thanks!

3:02 pm
May 3, 2010


c0d3r

Member

posts 5

7

update : the code didn't seem to work for me

not sure what is wrong

3:55 pm
May 3, 2010


Kevin

Admin

posts 2503

8

In RS Options (Features tab, Front End section), make sure you don't have "Assume No Front-end Admin" turned on.

Other than that, there's not much to go wrong. What is coming up empty - the $group object or the in_array check?

3:59 pm
May 3, 2010


Kevin

Admin

posts 2503

9

nslatter said:

How could I pull in a dynamic_sidebar for a specific RoleScoper group?

Not sure if I should start another topic altogether since the question seems to fit within this one.

Thanks!


Another topic would be better. I'm not sure exactly what you're asking for… directions on how to develop a widget, or just how to pull RS data to put into your widget shell. Or are you asking to generate a full sidebar as it would appear if a user of "group X" was logged in. Please answer in the new topic.


About the Agapetry forum

Currently Online:

13 Guests

Maximum Online: 150

Forums:

Groups: 2

Forums: 7

Topics: 1245

Posts: 5653

Members:

There are 1255 members

There are 1 guests


Kevin has made 2503 posts

Top Posters:

metal450 - 178

Ragnar - 108

YikYak - 70

whiteorb - 49

Daisy - 35

Administrator: Kevin | Moderators: Kevin