Skip to content
New issue

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

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

Already on GitHub? # to your account

Remove connection settings #502

Merged
merged 4 commits into from
Jul 20, 2018
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
2 changes: 1 addition & 1 deletion WP_Auth0.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Author URI: https://auth0.com
*/
define( 'WPA0_VERSION', '3.6.2' );
define( 'AUTH0_DB_VERSION', 18 );
define( 'AUTH0_DB_VERSION', 19 );

define( 'WPA0_PLUGIN_FILE', __FILE__ );
define( 'WPA0_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
Expand Down
1 change: 1 addition & 0 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ test:
phpcs --config-set installed_paths $HOME/.composer/vendor/wp-coding-standards/wpcs,$HOME/.composer/vendor/wimg/php-compatibility
override:
- phpcs --standard=$HOME/wp-auth0/phpcs-compat-ruleset.xml $HOME/wp-auth0 -pn -d memory_limit=-1
- phpcbf --standard=$HOME/wp-auth0/phpcs-compat-ruleset.xml $HOME/wp-auth0 -p -d memory_limit=-1
- |
rm -rf $WP_TESTS_DIR $WP_CORE_DIR
bash bin/install-wp-tests.sh wordpress_test ubuntu '' 127.0.0.1 3.8
Expand Down
6 changes: 3 additions & 3 deletions lib/WP_Auth0_Amplificator.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function share() {
}

public function get_share_text( $provider, $page_url ) {
$message = $this->a0_options->get_connection( "social_{$provider}_message" );
$message = $this->a0_options->get( "social_{$provider}_message" );

$message = str_replace( '%page_url%', $page_url, $message );
$message = str_replace( '%site_url%', home_url(), $message );
Expand Down Expand Up @@ -95,8 +95,8 @@ protected function _share_twitter( $page_url ) {
$share_text = $this->get_share_text( 'twitter', $page_url );

$settings = array(
'consumer_key' => $this->a0_options->get_connection( 'social_twitter_key' ),
'consumer_secret' => $this->a0_options->get_connection( 'social_twitter_secret' ),
'consumer_key' => $this->a0_options->get( 'social_twitter_key' ),
'consumer_secret' => $this->a0_options->get( 'social_twitter_secret' ),
'oauth_access_token' => $identity->access_token,
'oauth_access_token_secret' => $identity->access_token_secret,
);
Expand Down
2 changes: 2 additions & 0 deletions lib/WP_Auth0_Api_Operations.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ public function create_wordpress_connection( $app_token, $migration_enabled, $pa
}

/**
* TODO: Deprecate when self::update_connection() is deprecated
*
* This function will sync and update the connection setting with auth0
* First it checks if there is any connection with this strategy enabled for the app.
* - If exists, it checks if it has the facebook keys, in this case will ignore WP setting and will update the WP settings
Expand Down
19 changes: 17 additions & 2 deletions lib/WP_Auth0_DBManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class WP_Auth0_DBManager {
protected $current_db_version = null;
protected $a0_options;

public function __construct( $a0_options ) {
public function __construct( WP_Auth0_Options $a0_options ) {
$this->a0_options = $a0_options;
}

Expand All @@ -31,7 +31,7 @@ public function install_db( $version_to_install = null, $app_token = '' ) {

wp_cache_set( 'doing_db_update', true, WPA0_CACHE_GROUP );

$options = WP_Auth0_Options::Instance();
$options = $this->a0_options;

if ( empty( $app_token ) ) {
$app_token = $options->get( 'auth0_app_token' );
Expand Down Expand Up @@ -287,6 +287,21 @@ public function install_db( $version_to_install = null, $app_token = '' ) {
update_option( $options->get_options_name(), $update_options );
}

// 3.7.0
if ( ( $this->current_db_version < 19 && 0 !== $this->current_db_version ) || 19 === $version_to_install ) {
// Need to move settings values from child array to main array.
$connection_settings = $options->get( 'connections' );
if ( is_array( $connection_settings ) && ! empty( $connection_settings ) ) {
foreach ( $connection_settings as $setting => $value ) {
// If the setting is empty or if the main array has a value, skip.
if ( empty( $value ) || $options->get( $setting ) ) {
continue;
}
$options->set( $setting, $value );
}
}
}

$this->current_db_version = AUTH0_DB_VERSION;
update_option( 'auth0_db_version', AUTH0_DB_VERSION );

Expand Down
7 changes: 6 additions & 1 deletion lib/WP_Auth0_Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,19 @@ public function is_wp_registration_enabled() {
return is_multisite() ? users_can_register_#_filter() : get_site_option( 'users_can_register' );
}

/**
* TODO: Deprecate
*/
public function set_connection( $key, $value ) {
$options = $this->get_options();
$options['connections'][ $key ] = $value;

$this->set( 'connections', $options['connections'] );
}

/**
* TODO: Deprecate
*/
public function get_connection( $key, $default = null ) {
$options = $this->get_options();

Expand Down Expand Up @@ -172,7 +178,6 @@ protected function defaults() {
'last_step' => 1,
'migration_token_id' => null,
'jwt_auth_integration' => false,
'connections' => array(),
'auth0js-cdn' => WPA0_AUTH0_JS_CDN_URL,

// Basic
Expand Down
4 changes: 2 additions & 2 deletions lib/WP_Auth0_SocialAmplification_Widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ public function widget( $args, $instance ) {
$supportedProviders = array( 'facebook', 'twitter' );
$enabledProviders = array();

$social_facebook_key = $this->options->get_connection( 'social_facebook_key' );
$social_facebook_key = $this->options->get( 'social_facebook_key' );
if ( ! empty( $social_facebook_key ) ) {
$enabledProviders[] = 'facebook';
}

$social_twitter_key = $this->options->get_connection( 'social_twitter_key' );
$social_twitter_key = $this->options->get( 'social_twitter_key' );
if ( ! empty( $social_twitter_key ) ) {
$enabledProviders[] = 'twitter';
}
Expand Down
205 changes: 0 additions & 205 deletions lib/admin/WP_Auth0_Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,193 +6,6 @@ class WP_Auth0_Admin {

protected $router;

protected $providers = array(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We no longer control connections from the settings page so this is not needed.

array(
'provider' => 'facebook',
'name' => 'Facebook',
'icon' => 'Facebook',
'options' => array(
'public_profile' => true,
'email' => true,
'user_birthday' => true,
'publish_actions' => true,
),
),
array(
'provider' => 'twitter',
'name' => 'Twitter',
'icon' => 'Twitter',
'options' => array(
'profile' => true,
),
),
array(
'provider' => 'google-oauth2',
'name' => 'Google +',
'icon' => 'Google',
'options' => array(
'google_plus' => true,
'email' => true,
'profile' => true,
),
),
array(
'provider' => 'windowslive',
'name' => 'Microsoft Accounts',
'icon' => 'Windows LiveID',
),
array(
'provider' => 'yahoo',
'name' => 'Yahoo',
'icon' => 'Yahoo',
),
array(
'provider' => 'aol',
'name' => 'AOL',
'icon' => 'Aol',
),
array(
'provider' => 'linkedin',
'name' => 'Linkedin',
'icon' => 'LinkedIn',
),
array(
'provider' => 'paypal',
'name' => 'Paypal',
'icon' => 'PayPal',
),
array(
'provider' => 'github',
'name' => 'GitHub',
'icon' => 'GitHub',
),
array(
'provider' => 'amazon',
'name' => 'Amazon',
'icon' => 'Amazon',
),
array(
'provider' => 'vkontakte',
'name' => 'vkontakte',
'icon' => 'vk',
),
array(
'provider' => 'yandex',
'name' => 'yandex',
'icon' => 'Yandex Metrica',
),
array(
'provider' => 'thirtysevensignals',
'name' => 'thirtysevensignals',
'icon' => '37signals',
),
array(
'provider' => 'box',
'name' => 'box',
'icon' => 'Box',
),
array(
'provider' => 'salesforce',
'name' => 'salesforce',
'icon' => 'Salesforce',
),
array(
'provider' => 'salesforce-sandbox',
'name' => 'salesforce-sandbox',
'icon' => 'SalesforceSandbox',
),
array(
'provider' => 'salesforce-community',
'name' => 'salesforce-community',
'icon' => 'SalesforceCommunity',
),
array(
'provider' => 'fitbit',
'name' => 'Fitbit',
'icon' => 'Fitbit',
),
array(
'provider' => 'baidu',
'name' => '百度 (Baidu)',
'icon' => 'Baidu',
),
array(
'provider' => 'renren',
'name' => '人人 (RenRen)',
'icon' => 'RenRen',
),
array(
'provider' => 'weibo',
'name' => '新浪微 (Weibo)',
'icon' => 'Weibo',
),
array(
'provider' => 'shopify',
'name' => 'Shopify',
'icon' => 'Shopify',
),
array(
'provider' => 'dwolla',
'name' => 'Dwolla',
'icon' => 'dwolla',
),
array(
'provider' => 'miicard',
'name' => 'miiCard',
'icon' => 'miiCard',
),
array(
'provider' => 'wordpress',
'name' => 'wordpress',
'icon' => 'WordPress',
),
array(
'provider' => 'yammer',
'name' => 'Yammer',
'icon' => 'Yammer',
),
array(
'provider' => 'soundcloud',
'name' => 'soundcloud',
'icon' => 'Soundcloud',
),
array(
'provider' => 'instagram',
'name' => 'instagram',
'icon' => 'Instagram',
),
array(
'provider' => 'evernote',
'name' => 'evernote',
'icon' => 'Evernote',
),
array(
'provider' => 'evernote-sandbox',
'name' => 'evernote-sandbox',
'icon' => 'Evernote',
),
array(
'provider' => 'thecity',
'name' => 'thecity',
'icon' => 'The City',
),
array(
'provider' => 'thecity-sandbox',
'name' => 'thecity-sandbox',
'icon' => 'The City Sandbox',
),
array(
'provider' => 'planningcenter',
'name' => 'planningcenter',
'icon' => 'Planning Center',
),
array(
'provider' => 'exact',
'name' => 'exact',
'icon' => 'Exact',
),
);

protected $sections = array();

public function __construct( WP_Auth0_Options $a0_options, WP_Auth0_Routes $router ) {
Expand Down Expand Up @@ -288,8 +101,6 @@ public function input_validator( $input ) {

$old_options = $this->a0_options->get_options();

$input['connections'] = $old_options['connections'];

foreach ( $this->sections as $name => $section ) {
$input = $section->input_validator( $input, $old_options );
}
Expand All @@ -313,23 +124,7 @@ public function create_account_message() {
);
}

protected function get_social_connection( $provider, $name, $icon ) {
return array(
'name' => $name,
'provider' => $provider,
'icon' => $icon,
'status' => $this->a0_options->get_connection( "social_{$provider}" ),
'key' => $this->a0_options->get_connection( "social_{$provider}_key" ),
'secret' => $this->a0_options->get_connection( "social_{$provider}_secret" ),
);
}

public function render_settings_page() {
$social_connections = array();

foreach ( $this->providers as $provider ) {
$social_connections[] = $this->get_social_connection( $provider['provider'], $provider['name'], $provider['icon'] );
}

$domain = $this->a0_options->get( 'domain' );
$parts = explode( '.', $domain );
Expand Down
Loading