有一个动作钩在set_role
作用
这是一个检测主站点中是否发生这种情况的问题,如果发生,则获取用户的所有博客并更改所有角色。更多详细信息请参见代码注释。
add_action( \'set_user_role\', \'sync_user_roles_wpse_91745\', 10, 2 );
function sync_user_roles_wpse_91745( $user_id, $role )
{
// is_multisite() used just as precaution, this code is meant to Multisite only
if( !is_multisite() || !is_main_site() )
return;
// Initial data
$blogs = get_blogs_of_user( $user_id );
$original_blog_id = get_current_blog_id();
// Remove main site from affected sites
unset( $blogs[ $original_blog_id ] );
// Iterate through blogs of user
foreach ( $blogs as $blog )
{
// Work with another site
switch_to_blog( $blog->userblog_id );
// Grab all user info and update role as in main site
$site_user = get_user_by( \'id\', $user_id );
$site_user->set_role( $role );
}
// Back to original main site
switch_to_blog( $original_blog_id );
}
我不知道,但在整个网络中,用户ID在表中保持不变
wp_users
和
wp_{$site_id}_users
.