You can write a small custom function, that loop about the network and add in each site of the network the new role. See the source below als example to add_role. If you like update or change a existing role, then switch from add_role
to add_cap
.
function fb_change_role_network_wide( $role ) {
global $wpdb;
$args = $args = array(
'network_id' => $wpdb->siteid,
'public' => null,
'archived' => null,
'mature' => null,
'spam' => null,
'deleted' => null,
'limit' => 100,
'offset' => 0,
);
$sites = wp_get_sites( $args );
$role="contributor";
$display_name="Test Priv";
$capabilities = array( ... );
foreach( $sites as $key => $blog ) {
switch_to_blog( $blog[ 'blog_id' ] );
add_role( $role, $display_name, $capabilities );
restore_current_blog();
}
}
The important part to add a object in each site of the network is the loop and the core functions:
switch_to_blog( $blog[ 'blog_id' ] );
...
restore_current_blog();
Inside this loop add your requirements with the parameters and it will doing this in each site.
Enhanced, also a small example to add users, identify via User-ID to each site of the network.
function fb_add_roles( $user_id ) {
global $wpdb;
$args = $args = array(
'network_id' => $wpdb->siteid,
'public' => null,
'archived' => null,
'mature' => null,
'spam' => null,
'deleted' => null,
'limit' => 100,
'offset' => 0,
);
$sites = wp_get_sites( $args );
$role="contributor";
foreach( $sites as $key => $blog ) {
if ( is_user_member_of_blog( $user_id, $blog[ 'blog_id' ] ) ) {
continue;
}
switch_to_blog( $blog[ 'blog_id' ] );
add_user_to_blog( $blog[ 'blog_id' ], $user_id, $role );
restore_current_blog();
}
}