Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.