diff --git a/README.md b/README.md index 93cdebb..63fdaa9 100644 --- a/README.md +++ b/README.md @@ -95,9 +95,9 @@ There are 2 filters available here: ### SSO -10up Experience includes 10up SSO functionality. There are some useful constants related to this functionality: +10up Experience includes 10up SSO functionality. This feature can be enabled or disabled in `Settings > General`. It is enabled by default. There are some useful constants related to this functionality: -- `TENUPSSO_DISABLE` - Define this as `true` to disable SSO. +- `TENUPSSO_DISABLE` - Define this as `true` to force disable SSO. - `TENUPSSO_DISALLOW_ALL_DIRECT_LOGIN` - Define this as `true` to disable username/password log ins completely. ### Activity Log diff --git a/includes/classes/SSO/SSO.php b/includes/classes/SSO/SSO.php index e011808..305e15e 100644 --- a/includes/classes/SSO/SSO.php +++ b/includes/classes/SSO/SSO.php @@ -31,6 +31,17 @@ public function setup() { return; } + if ( TENUP_EXPERIENCE_IS_NETWORK ) { + add_action( 'wpmu_options', [ $this, 'ms_settings' ] ); + add_action( 'admin_init', [ $this, 'ms_save_settings' ] ); + } else { + add_action( 'admin_init', [ $this, 'single_site_setting' ] ); + } + + if ( 'yes' !== $this->get_setting() ) { + return; + } + if ( defined( 'TENUPSSO_DISALLOW_ALL_DIRECT_LOGIN' ) && TENUPSSO_DISALLOW_ALL_DIRECT_LOGIN ) { add_filter( 'allow_password_reset', '__return_false' ); } @@ -43,6 +54,119 @@ public function setup() { add_action( 'admin_page_access_denied', [ $this, 'check_user_blog' ] ); } + /** + * Set options in multisite + */ + public function ms_save_settings() { + global $pagenow; + if ( ! is_network_admin() ) { + return; + } + + if ( 'settings.php' !== $pagenow ) { + return; + } + + if ( ! is_super_admin() ) { + return; + } + + if ( empty( $_POST['_wpnonce'] ) || ! wp_verify_nonce( $_POST['_wpnonce'], 'siteoptions' ) ) { + return; + } + + if ( ! isset( $_POST['tenup_allow_sso'] ) ) { + return; + } + + $setting = $this->validate_sso_setting( $_POST['tenup_allow_sso'] ); + + update_site_option( 'tenup_allow_sso', $setting ); + } + + /** + * Output multisite settings + */ + public function ms_settings() { + $setting = $this->get_setting(); + ?> +
+ ++ |
+ type="radio" id="tenup_allow_sso_yes" value="yes"> + type="radio" id="tenup_allow_sso_no" value="no"> + |
+
---|