Skip to content

Instantly share code, notes, and snippets.

@fjorgemota
Forked from claudiosanches/functions.php
Created August 31, 2012 01:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fjorgemota/3547434 to your computer and use it in GitHub Desktop.
Save fjorgemota/3547434 to your computer and use it in GitHub Desktop.
WP Is Current User
<?php
/**
* Verifica o papel do usuário.
*
* Exempo de uso:
* if (is_current_user('administrator')) {
* echo 'Olá administrador';
* }
*
* @param string $user
* Indicar o papel do usuário que deseja testar.
* @return bool
*/
function is_current_user($user) {
$return = false;
$current_user = wp_get_current_user();
switch($user) {
case 'administrator':
$return = isset($current_user->caps['administrator']);
break;
case 'editor':
case 'author':
$return = isset($current_user->caps['editor']);
break;
case 'contributor':
$return = isset($current_user->caps['contributor']);
break;
case 'subscriber':
$return = isset($current_user->caps['subscriber']);
break;
default:
break;
}
return $return;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment