Created
August 21, 2012 04:16
-
-
Save claudiosanches/3411470 to your computer and use it in GitHub Desktop.
WP Is Current User
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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']) ? true : false; | |
break; | |
case 'editor': | |
$return = isset($current_user->caps['editor']) ? true : false; | |
break; | |
case 'author': | |
$return = isset($current_user->caps['editor']) ? true : false; | |
break; | |
case 'contributor': | |
$return = isset($current_user->caps['contributor']) ? true : false; | |
break; | |
case 'subscriber': | |
$return = isset($current_user->caps['subscriber']) ? true : false; | |
break; | |
default: | |
break; | |
} | |
return $return; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment