Skip to content

Commit

Permalink
Merge pull request #6 from a8cteam51/fix/1-disable-sso-not-prod
Browse files Browse the repository at this point in the history
Enable/Disable sso based on env type
  • Loading branch information
bernattorras authored Nov 20, 2023
2 parents 3690016 + 3bbc4fd commit 332ca87
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
21 changes: 14 additions & 7 deletions includes/class-force-sso.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ public static function init() {

$force_sso = new static();

// Bail if it is a staging, development or local site (only force SSO on producion sites).
if ( 'production' !== wp_get_environment_type() ) {
return;
}

add_filter( 'jetpack_active_modules', array( $force_sso, 'activate_sso' ) );
add_action( 'jetpack_module_loaded_sso', array( $force_sso, 'sso_loaded' ) );

Expand All @@ -37,8 +32,20 @@ public static function init() {
* @return array
*/
public function activate_sso( array $modules ): array {
if ( false === array_search( 'sso', $modules, true ) ) {
$modules[] = 'sso';
$environment_type = wp_get_environment_type();

// Check if the 'sso' module should be enabled or disabled based on the environment type.
if ( 'production' === $environment_type ) {
// Add 'sso' module if it's not already enabled.
if ( false === array_search( 'sso', $modules, true ) ) {
$modules[] = 'sso';
}
} else {
// Disable 'sso' module if it's enabled on a non-production site.
$index = array_search( 'sso', $modules, true );
if ( false !== $index ) {
unset( $modules[ $index ] );
}
}

return $modules;
Expand Down
2 changes: 1 addition & 1 deletion to51-jetpack-force-sso.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Force "Allow users to log in to this site using WordPress.com accounts".
* Force "Match accounts using email addresses".
* Force "Require accounts to use WordPress.com Two-Step Authentication".
* Version: 1.0.2
* Version: 1.0.3
* Author: WordPress.com Special Projects Team
* Author URI: https://wpspecialprojects.wordpress.com
* Text Domain: to51-jetpack-force-sso
Expand Down

0 comments on commit 332ca87

Please sign in to comment.