@requires @plugin Members
// Sync roles across multisite network by hooking to Members plugin (https://wordpress.org/plugins/members/)
add_action( 'members_role_updated', function() {
if ( function_exists( 'get_sites' ) && class_exists( 'WP_Site_Query' ) ) {
$roles = get_option( 'wp_user_roles' );
$sites = get_sites( array( 'fields' => 'ids' ) );
foreach ( $sites as $site_id ) {
update_blog_option( $site_id, 'wp_' . $site_id . '_user_roles', $roles );
}
}
} );