wp_get_users_with_no_role
函数
wp_get_users_with_no_role ( $site_id = null )
- 参数
-
-
(int|null)
$site_id
Optional. The site ID to get users with no role for. Defaults to the current site.- Required: 否
- Default: null
-
(int|null)
- 返回值
-
- (string[]) Array of user IDs as strings.
- 定义位置
-
-
wp-includes/user.php
, line 3511
-
wp-includes/user.php
- 引入
- 4.4.0
- 弃用
- –
Gets the user IDs of all users with no role on this site.
function wp_get_users_with_no_role( $site_id = null ) {
global $wpdb;
if ( ! $site_id ) {
$site_id = get_current_blog_id();
}
$prefix = $wpdb->get_blog_prefix( $site_id );
if ( is_multisite() && get_current_blog_id() != $site_id ) {
switch_to_blog( $site_id );
$role_names = wp_roles()->get_names();
restore_current_blog();
} else {
$role_names = wp_roles()->get_names();
}
$regex = implode( '|', array_keys( $role_names ) );
$regex = preg_replace( '/[^a-zA-Z_|-]/', '', $regex );
$users = $wpdb->get_col(
$wpdb->prepare(
"
SELECT user_id
FROM $wpdb->usermeta
WHERE meta_key = '{$prefix}capabilities'
AND meta_value NOT REGEXP %s
",
$regex
)
);
return $users;
}
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。