[wp-trac] [WordPress Trac] #39944: Site wp_X_user_roles option not updated when network settings change
WordPress Trac
noreply at wordpress.org
Wed Feb 22 19:11:02 UTC 2017
#39944: Site wp_X_user_roles option not updated when network settings change
--------------------------------+-----------------------------
Reporter: sanchothefat | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Networks and Sites | Version: 4.5
Severity: normal | Keywords:
Focuses: multisite |
--------------------------------+-----------------------------
When a new site is created there is a call to `populate_roles()` which
builds and saves a site option called `wp_X_user_roles` where `X` is the
blog ID.
If you have "Administrators can add new users" unchecked and create a
site, then check it and create another site - the two new sites will have
different user roles arrays, the first of which will no longer represent
the chosen network settings.
WP should handle updating the `wp_X_user_roles` option across the network
when either the `add_new_users` or the `registration` site options change.
The following is an intermediate workaround for this but isn't necessarily
very scalable:
{{{#!php
<?php
/**
* Currently when network settings are updated the capabilties for each
* site stay as they were at the time of creation
*
* @action wpmuadminedit Runs before options are updated
*/
add_action( 'wpmuadminedit', function() {
$do_update_roles = false;
if ( isset( $_POST['add_new_users'] ) !== (bool) get_site_option(
'add_new_users' ) ) {
$do_update_roles = true;
}
if ( $_POST['registration'] !== get_site_option( 'registration' )
) {
$do_update_roles = true;
}
if ( ! $do_update_roles ) {
return;
}
/**
* Runs after settings have been updated
*/
add_action( 'update_wpmu_options', function() {
// Need populate_roles() function
require_once ABSPATH . '/wp-admin/includes/schema.php';
if ( function_exists( 'get_sites' ) ) {
$blog_ids = get_sites( array(
'fields' => 'ids'
) );
} else {
$blog_ids = array_map( function( $site ) {
return $site['blog_id'];
}, wp_get_sites() );
}
// Call populate_roles() for each site
foreach( $blog_ids as $blog_id ) {
switch_to_blog( $blog_id );
populate_roles();
restore_current_blog();
}
} );
} );
}}}
Any thoughts on the best way to update this option? Eg. when visiting the
individual site admin, could we somehow tell if that network setting has
been changed since the last run of `populate_roles()`?
--
Ticket URL: <https://core.trac.wordpress.org/ticket/39944>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list