在设置规则之前,必须删除筛选器。请参见下面的代码示例:
// Sync user role
add_action( \'set_user_role\', \'sync_user_role\', 10, 2 );
function sync_user_role( $user_id, $role ) {
$blogs = get_blogs_of_user( $user_id );
$blogs_count = count( $blogs );
if ( $blogs_count > 1 ) {
foreach ( $blogs as $blog ) {
$user_blog = new WP_User( $user_id, \'\', $blog->userblog_id );
remove_action( \'set_user_role\', \'sync_user_role\', 10);
$user_blog->set_role( $role );
add_action( \'set_user_role\', \'sync_user_role\', 10, 2 );
}
}
}