Last active
April 2, 2020 18:08
-
-
Save MaximeCulea/f15d1268a3056c7a6a2c732ed043166c to your computer and use it in GitHub Desktop.
Cheatset for multinetwork
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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