Conditional tags 用于根据页面满足的条件更改内容。虽然没有依赖于用户角色的条件标记,但这是您可以根据角色操作内容的方式:
Display content to the user, depending on his role
<?php
global $current_user;
get_currentuserinfo(); //not strictly required, $current_user should be populated anyway
if(in_array(\'editor\', $current_user->roles)) {
// echo markup here
}
?>
或者,您可能还想签出
current_user_can()
Edit: Display content based on a commentator\'s role
<?php
$commentator_id = get_comment(get_comment_ID())->user_id;
$commentator_info = get_userdata($commentator_id);
$capabilities = $user_info->wp_capabilities;
if (array_key_exists(\'editor\', $capabilities)) {
// echo markup here
}
?>
以上内容必须放在注释循环中。
资源:get_comment() | get_user_data() | Comment Loop Beauty