I recently had a problem finding a WordPress function to detect if a user has a roles and assign a task via PHP.
Here is are functions to detect if a user is an Administrator, Editor, subscriber e.t.c.
<?php
if( current_user_can('subscriber') ) {
// true if user is a subscriber
}
if( current_user_can('editor') ) {
// true if user is an editor
}
if( !current_user_can('administrator') ) {
// true if user is not admin
}
if( current_user_can('edit_posts') ) {
// true if user can edit posts
}
if( !current_user_can('edit_posts') ) {
// true if user cannot edit post
}
if( current_user_can('moderate_comments') ) {
// true if user can moderate comment
}
if ( current_user_can('edit_post', 123) ) {
// true if user can edit post with ID 123'.
}
?>
Check WordPress Codex for full list of roles and capabilities.