Created
April 1, 2020 10:57
-
-
Save wpmudev-sls/31b662736b8caee5748c3775c1a51705 to your computer and use it in GitHub Desktop.
[Defender] Load Roles From All Sub Sites
This file contains hidden or 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 | |
/** | |
* Plugin Name: [Defender] Load Roles From All Sub Sites | |
* Plugin URI: https://premium.wpmudev.org/ | |
* Description: If the current url is from "advanced tools" configuration page and the site is multisite, this plugin load all roles from the multisite network. In this way, we make it possible to configure 2-factor authentication for any role present on any of the sites of the entire network. | |
* Author: Glauber Silva @ WPMUDEV | |
* Author URI: https://premium.wpmudev.org/ | |
* Task: 0/11289012348292/1168965543535336 | |
* License: GPLv2 or later | |
* | |
* @package Defender_Load_Roles_From_All_Child_Sites | |
*/ | |
defined( 'ABSPATH' ) || exit; | |
/** | |
* Filters the list of editable roles. | |
* | |
* @since 2.8.0 | |
* | |
* @param array[] $all_roles Array of arrays containing role information. | |
*/ | |
function wpmudev_get_roles_from_all_sites( $all_roles ) { | |
if ( is_multisite() && isset( $_GET['page'] ) && 'wdf-advanced-tools' === $_GET['page'] ) { //phpcs:ignore | |
$sites = get_sites(); | |
if ( ! empty( $sites ) ) { | |
foreach ( $sites as $site ) { | |
switch_to_blog( $site->blog_id ); | |
$roles_current_site = wp_roles()->roles; | |
$all_roles = array_merge( $all_roles, $roles_current_site ); | |
restore_current_blog(); | |
} | |
} | |
} | |
return $all_roles; | |
} | |
add_filter( 'editable_roles', 'wpmudev_get_roles_from_all_sites' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment