| User | Post |
|
7:45 am April 20, 2010
| c0d3r
Member
| | | |
|
| posts 5 |
|
|
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 |
|
|
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 |
|
|
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 |
|
|
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 |
|
|
|
2:19 pm May 3, 2010
| nslatter
Member
| | | |
|
| posts 2 |
|
|
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 |
|
|
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 |
|
|
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 |
|
|
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.
|
|