diff --git a/lib/WP_Auth0_Lock10_Options.php b/lib/WP_Auth0_Lock10_Options.php index 9872a947..c42fbc92 100644 --- a/lib/WP_Auth0_Lock10_Options.php +++ b/lib/WP_Auth0_Lock10_Options.php @@ -168,7 +168,7 @@ protected function build_settings( $settings ) { } } if ( $this->_is_valid( $settings, 'lock_connections' ) ) { - $options_obj['allowedConnections'] = explode( ",", $settings['lock_connections'] ); + $options_obj['allowedConnections'] = $this->wp_options->get_lock_connections(); } if ( isset( $settings['extra_conf'] ) && trim( $settings['extra_conf'] ) !== '' ) { $extra_conf_arr = json_decode( $settings['extra_conf'], true ); diff --git a/lib/WP_Auth0_Lock_Options.php b/lib/WP_Auth0_Lock_Options.php index 236921ba..a699c452 100644 --- a/lib/WP_Auth0_Lock_Options.php +++ b/lib/WP_Auth0_Lock_Options.php @@ -160,7 +160,7 @@ protected function build_settings( $settings ) { $options_obj['icon'] = $settings['icon_url']; } if ( $this->_is_valid( $settings, 'lock_connections' ) ) { - $options_obj['connections'] = explode( ",", $settings['lock_connections'] ); + $options_obj['connections'] = $this->wp_options->get_lock_connections(); } if ( isset( $settings['extra_conf'] ) && trim( $settings['extra_conf'] ) !== '' ) { $extra_conf_arr = json_decode( $settings['extra_conf'], true ); diff --git a/lib/WP_Auth0_Options.php b/lib/WP_Auth0_Options.php index 82bcc023..1bb0b84a 100755 --- a/lib/WP_Auth0_Options.php +++ b/lib/WP_Auth0_Options.php @@ -2,16 +2,16 @@ class WP_Auth0_Options extends WP_Auth0_Options_Generic { - protected static $instance = null; + protected static $_instance = null; + protected $_options_name = 'wp_auth0_settings'; + public static function Instance() { - if ( self::$instance === null ) { - self::$instance = new WP_Auth0_Options; + if ( null=== self::$_instance ) { + self::$_instance = new WP_Auth0_Options; } - return self::$instance; + return self::$_instance; } - protected $options_name = 'wp_auth0_settings'; - public function is_wp_registration_enabled() { if ( is_multisite() ) { return users_can_register_signup_filter(); @@ -19,6 +19,7 @@ public function is_wp_registration_enabled() { return get_site_option( 'users_can_register', 0 ) == 1; } + // TODO: Deprecate, not used public function get_enabled_connections() { return array( 'facebook', 'twitter', 'google-oauth2' ); } @@ -43,9 +44,13 @@ public function get_default($key) { return $defaults[$key]; } + /** + * Get the stored token signing algorithm + * + * @return string + */ public function get_client_signing_algorithm() { - $client_signing_algorithm = $this->get('client_signing_algorithm', WP_Auth0_Api_Client::DEFAULT_CLIENT_ALG); - return $client_signing_algorithm; + return $this->get( 'client_signing_algorithm', WP_Auth0_Api_Client::DEFAULT_CLIENT_ALG ); } /** @@ -129,92 +134,124 @@ public function get_logout_url() { return add_query_arg( 'action', 'logout', site_url( 'wp-login.php', 'login' ) ); } + /** + * Get lock_connections as an array of strings + * + * @return array + */ + public function get_lock_connections() { + $connections = $this->get( 'lock_connections' ); + $connections = empty( $connections ) ? array() : explode( ',', $connections ); + return array_map( 'trim', $connections ); + } + + /** + * Add a new connection to the lock_connections setting + * + * @param string $connection - connection name to add + */ + public function add_lock_connection( $connection ) { + $connections = $this->get_lock_connections(); + + // Add if it doesn't exist already + if ( ! array_key_exists( $connection, $connections ) ) { + $connections[] = $connection; + $connections = implode( ',', $connections ); + $this->set( 'lock_connections', $connections ); + } + } + + /** + * Default settings when plugin is installed or reset + * + * @return array + */ protected function defaults() { return array( + + // System 'version' => 1, - 'metrics' => 1, 'last_step' => 1, - 'auto_login' => 0, - 'auto_login_method' => '', + 'migration_token_id' => null, + 'use_lock_10' => true, + 'jwt_auth_integration' => false, + 'amplificator_title' => '', + 'amplificator_subtitle' => '', + 'connections' => array(), + 'auth0js-cdn' => 'https://cdn.auth0.com/js/auth0/9.1/auth0.min.js', + + // Basic + 'domain' => '', 'client_id' => '', 'client_secret' => '', + 'client_secret_b64_encoded' => null, 'client_signing_algorithm' => WP_Auth0_Api_Client::DEFAULT_CLIENT_ALG, 'cache_expiration' => 1440, - 'client_secret_b64_encoded' => null, - 'domain' => '', - 'form_title' => '', - 'icon_url' => '', - 'ip_range_check' => 0, - 'ip_ranges' => '', - 'lock_connections' => '', - 'passwordless_enabled' => false, - 'passwordless_method' => 'magiclink', - 'passwordless_cdn_url' => '//cdn.auth0.com/js/lock-passwordless-2.2.min.js', - 'use_lock_10' => true, - 'cdn_url' => '//cdn.auth0.com/js/lock/11.1/lock.min.js', - 'cdn_url_legacy' => '//cdn.auth0.com/js/lock-9.2.min.js', - 'requires_verified_email' => true, + 'auth0_app_token' => null, 'wordpress_login_enabled' => true, - 'primary_color' => '', - 'language' => '', - 'language_dictionary' => '', - - 'custom_signup_fields' => '', - - 'social_big_buttons' => false, - 'username_style' => '', - 'extra_conf' => '', - 'custom_css' => '', - 'custom_js' => '', - 'auth0_implicit_workflow' => false, + // Features + 'password_policy' => 'fair', 'sso' => false, 'singlelogout' => false, - 'gravatar' => true, - 'jwt_auth_integration' => false, - 'auth0_app_token' => null, - 'api_audience' => null, 'mfa' => null, 'fullcontact' => null, - 'fullcontact_rule' => null, 'fullcontact_apikey' => null, 'geo_rule' => null, 'income_rule' => null, - 'link_auth0_users' => null, - 'remember_users_session' => false, - 'override_wp_avatars' => true, + // Appearance + 'icon_url' => '', + 'form_title' => '', + 'social_big_buttons' => false, + 'gravatar' => true, + 'custom_css' => '', + 'custom_js' => '', + 'username_style' => '', + 'primary_color' => '', + 'language' => '', + 'language_dictionary' => '', + + // Advanced + 'requires_verified_email' => true, + 'remember_users_session' => false, + 'default_login_redirection' => home_url(), + 'passwordless_enabled' => false, + 'passwordless_method' => 'magiclink', + 'force_https_callback' => false, + 'cdn_url' => 'https://cdn.auth0.com/js/lock/11.1/lock.min.js', + 'cdn_url_legacy' => 'https://cdn.auth0.com/js/lock-9.2.min.js', + 'passwordless_cdn_url' => 'https://cdn.auth0.com/js/lock-passwordless-2.2.min.js', + 'lock_connections' => '', + 'link_auth0_users' => null, + 'auto_provisioning' => false, 'migration_ws' => false, 'migration_token' => null, - 'migration_token_id' => null, 'migration_ips_filter' => false, 'migration_ips' => null, + 'auto_login' => 0, + 'auto_login_method' => '', + 'auth0_implicit_workflow' => false, + 'ip_range_check' => 0, + 'ip_ranges' => '', 'valid_proxy_ip' => null, - - 'amplificator_title' => '', - 'amplificator_subtitle' => '', - - 'connections' => array(), - - 'password_policy' => 'fair', - - 'force_https_callback' => false, - - 'auto_provisioning' => false, - 'default_login_redirection' => home_url(), - + 'custom_signup_fields' => '', + 'extra_conf' => '', + 'social_twitter_key' => '', + 'social_twitter_secret' => '', + 'social_facebook_key' => '', + 'social_facebook_secret' => '', 'auth0_server_domain' => 'auth0.auth0.com', - 'auth0js-cdn' => '//cdn.auth0.com/js/auth0/9.1/auth0.min.js', + 'metrics' => 1, - //DASHBOARD + // Dashboard 'chart_idp_type' => 'donut', 'chart_gender_type' => 'donut', 'chart_age_type' => 'donut', - 'chart_age_from' => '10', 'chart_age_to' => '70', 'chart_age_step' => '5', ); } -} +} \ No newline at end of file diff --git a/lib/WP_Auth0_Options_Generic.php b/lib/WP_Auth0_Options_Generic.php index e353293f..a9d708bb 100644 --- a/lib/WP_Auth0_Options_Generic.php +++ b/lib/WP_Auth0_Options_Generic.php @@ -1,16 +1,16 @@ options_name; + return $this->_options_name; } public function get_options() { if ( empty( $this->_opt ) ) { - $options = get_option( $this->options_name, array() ); + $options = get_option( $this->_options_name, array() ); if ( !is_array( $options ) ) $options = $this->defaults(); @@ -36,23 +36,23 @@ public function set( $key, $value, $should_update = true ) { $this->_opt = $options; if ( $should_update ) { - update_option( $this->options_name, $options ); + update_option( $this->_options_name, $options ); } } public function update_all() { - update_option( $this->options_name, $this->_opt ); + update_option( $this->_options_name, $this->_opt ); } public function save() { $options = $this->get_options(); - update_option( $this->options_name, $options ); + update_option( $this->_options_name, $options ); } public function delete() { - delete_option( $this->options_name ); + delete_option( $this->_options_name ); } protected function defaults() { return array(); } -} +} \ No newline at end of file diff --git a/lib/admin/WP_Auth0_Admin_Advanced.php b/lib/admin/WP_Auth0_Admin_Advanced.php index fb20204a..3f37c044 100644 --- a/lib/admin/WP_Auth0_Admin_Advanced.php +++ b/lib/admin/WP_Auth0_Admin_Advanced.php @@ -556,8 +556,6 @@ public function connections_validation( $old_options, $input ) { if ($input['passwordless_enabled'] && $input['passwordless_enabled'] != $old_options['passwordless_enabled']) { - // $check_if_enabled = explode(',', $input['lock_connections']); - foreach ($passwordless_connections as $alias => $name) { if (strpos($input['passwordless_method'], $alias) !== false) { $check_if_enabled[] = $name; @@ -566,19 +564,12 @@ public function connections_validation( $old_options, $input ) { } elseif ($input['passwordless_method'] != $old_options['passwordless_method']) { - // $check_if_enabled = explode(',', $input['lock_connections']); - foreach ($passwordless_connections as $name) { if (strpos($input['passwordless_method'], $name) !== false) { $check_if_enabled[] = $name; } } - - } // elseif ($input['lock_connections'] != $old_options['lock_connections']) { - - // $check_if_enabled = explode(',', $input['lock_connections']); - - // } + } if (!empty($check_if_enabled)) {