我想编写一些能够识别特定wordpress用户角色的东西。 有人知道下面角色的相应数字吗?
例如:谁是level_0
?谁是level_1
?
答案 0 :(得分:10)
来自codex
User Level 0 converts to Subscriber
User Level 1 converts to Contributor
User Level 2 converts to Author
User Level 3 converts to Editor
User Level 4 converts to Editor
User Level 5 converts to Editor
User Level 6 converts to Editor
User Level 7 converts to Editor
User Level 8 converts to Administrator
User Level 9 converts to Administrator
User Level 10 converts to Administrator
答案 1 :(得分:1)
这是一篇很好的文章,它解释了如何获得所有用户名单:
http://sltaylor.co.uk/blog/get-wordpress-users-by-role/
如果你在你的功能中设置它并请求它,你应该得到所有角色:
function getUsersByRole( $roles ) {
global $wpdb;
if ( ! is_array( $roles ) ) {
$roles = explode( ",", $roles );
array_walk( $roles, 'trim' );
}
$sql = '
SELECT ID, display_name
FROM ' . $wpdb->users . ' INNER JOIN ' . $wpdb->usermeta . '
ON ' . $wpdb->users . '.ID = ' . $wpdb->usermeta . '.user_id
WHERE ' . $wpdb->usermeta . '.meta_key = \'' . $wpdb->prefix . 'capabilities\'
AND (
';
$i = 1;
foreach ( $roles as $role ) {
$sql .= ' ' . $wpdb->usermeta . '.meta_value LIKE \'%"' . $role . '"%\' ';
if ( $i < count( $roles ) ) $sql .= ' OR ';
$i++;
}
$sql .= ' ) ';
$sql .= ' ORDER BY display_name ';
$userIDs = $wpdb->get_col( $sql );
return $userIDs;
}