Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable/Disable sso based on env type #6

Merged
merged 1 commit into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading