Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Cheatset for multinetwork
<?php
/**
* Grant newly superadmin user to all networks when working in a multi-network context
* @author Maxime CULEA
*/
add_action( 'grant_super_admin', 'superadmin_is_superadmin_for_all_networks' );
function superadmin_is_superadmin_for_all_networks( $user_id ) {
remove_action( 'grant_super_admin', 'superadmin_is_superadmin_for_all_networks' );
global $wpdb;
$results = $wpdb->get_col( "SELECT id FROM {$wpdb->site}" );
if ( ! empty( $results ) ) {
$current_network = get_current_network_id();
foreach ( $results as $network_id ) {
switch_to_network( (int) $network_id );
grant_super_admin( $user_id );
}
switch_to_network( $current_network );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.