From f6c0bcdec16b87405d489dfdcf12710fa5e36166 Mon Sep 17 00:00:00 2001
From: Patrick Groot <info@patrickgroot.com>
Date: Tue, 22 Sep 2020 13:46:12 +0200
Subject: [PATCH 1/9] 1st commit

WIP #8
---
 socialify.php | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/socialify.php b/socialify.php
index c32bde4..3582bc8 100644
--- a/socialify.php
+++ b/socialify.php
@@ -79,6 +79,11 @@ public static function init()
 
         add_action('init', [__CLASS__, 'add_endpoint']);
 
+		add_action( 'plugins_loaded', [__CLASS__, 'socialify_textdomain']);
+
+		add_action( 'show_user_profile', [__CLASS__, 'socialify_user_profile_settings']);
+		add_action( 'edit_user_profile', [__CLASS__, 'socialify_user_profile_settings']);
+
         add_filter( "plugin_action_links_" . self::$plugin_basename, [__CLASS__, 'add_settings_url_to_plugins_list'] );
 
         add_action('admin_menu', function(){
@@ -319,6 +324,39 @@ public static function add_endpoint()
         }
     }
 
+	public static function socialify_textdomain() {
+		load_plugin_textdomain( 'socialify', FALSE, basename( dirname( __FILE__ ) ) . '/languages/' );
+	}
+
+	public static function socialify_user_profile_settings( $user ) {
+		?>
+		<h3><?php esc_html_e( 'Socialify Settings', 'socialify' ); ?></h3>
+
+		<table class="form-table">
+			<tr>
+				<th><label for="facebook_sso"><?php esc_html_e( 'Facebook SSO', 'socialify' ); ?></label></th>
+				<td>
+					<?php if(true) { ?> 
+						<button type="button" name="facebook_sso" id="facebook_sso" class="button hide-if-no-js"><?= __('Connect', 'socialify'); ?></button>
+					<?php } else { ?>
+						<button type="button" name="facebook_sso" id="facebook_sso" class="button hide-if-no-js"><?= __('Disconnect', 'socialify'); ?></button>
+					<?php } ?>
+				</td>
+			</tr>
+			<tr>
+				<th><label for="google_sso"><?php esc_html_e( 'Google SSO', 'socialify' ); ?></label></th>
+				<td>
+					<?php if(true) { ?> 
+						<button type="button" name="google_sso" id="google_sso" class="button hide-if-no-js"><?= __('Connect', 'socialify'); ?></button>
+					<?php } else { ?>
+						<button type="button" name="google_sso" id="google_sso"class="button hide-if-no-js"><?= __('Disconnect', 'socialify'); ?></button>
+					<?php } ?>
+				</td>
+			</tr>
+		</table>
+		<?php
+	}
+
 }
 
 General::init();

From 7ead1fd45cfc393ed49c7093b899bf257763a667 Mon Sep 17 00:00:00 2001
From: Patrick Groot <info@patrickgroot.com>
Date: Tue, 22 Sep 2020 14:03:18 +0200
Subject: [PATCH 2/9] Update socialify.php

---
 socialify.php | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/socialify.php b/socialify.php
index 3582bc8..0f9c449 100644
--- a/socialify.php
+++ b/socialify.php
@@ -336,7 +336,8 @@ public static function socialify_user_profile_settings( $user ) {
 			<tr>
 				<th><label for="facebook_sso"><?php esc_html_e( 'Facebook SSO', 'socialify' ); ?></label></th>
 				<td>
-					<?php if(true) { ?> 
+					<?php $connected == true; 
+					if( $connected == false ) { ?> 
 						<button type="button" name="facebook_sso" id="facebook_sso" class="button hide-if-no-js"><?= __('Connect', 'socialify'); ?></button>
 					<?php } else { ?>
 						<button type="button" name="facebook_sso" id="facebook_sso" class="button hide-if-no-js"><?= __('Disconnect', 'socialify'); ?></button>
@@ -346,7 +347,8 @@ public static function socialify_user_profile_settings( $user ) {
 			<tr>
 				<th><label for="google_sso"><?php esc_html_e( 'Google SSO', 'socialify' ); ?></label></th>
 				<td>
-					<?php if(true) { ?> 
+					<?php $connected == true;
+					if( $connected == true ) { ?> 
 						<button type="button" name="google_sso" id="google_sso" class="button hide-if-no-js"><?= __('Connect', 'socialify'); ?></button>
 					<?php } else { ?>
 						<button type="button" name="google_sso" id="google_sso"class="button hide-if-no-js"><?= __('Disconnect', 'socialify'); ?></button>

From 05ad3c2f10989a59615e8e5628384424e06d8d6f Mon Sep 17 00:00:00 2001
From: Patrick Groot <info@patrickgroot.com>
Date: Tue, 22 Sep 2020 15:58:04 +0200
Subject: [PATCH 3/9] Update socialify.php

---
 socialify.php | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/socialify.php b/socialify.php
index 0f9c449..4c94773 100644
--- a/socialify.php
+++ b/socialify.php
@@ -329,10 +329,13 @@ public static function socialify_textdomain() {
 	}
 
 	public static function socialify_user_profile_settings( $user ) {
+
+		if ( $facebook || $google == is_active() ) {
 		?>
 		<h3><?php esc_html_e( 'Socialify Settings', 'socialify' ); ?></h3>
 
 		<table class="form-table">
+			<?php if ( $facebook == is_active() ) { ?>
 			<tr>
 				<th><label for="facebook_sso"><?php esc_html_e( 'Facebook SSO', 'socialify' ); ?></label></th>
 				<td>
@@ -344,6 +347,9 @@ public static function socialify_user_profile_settings( $user ) {
 					<?php } ?>
 				</td>
 			</tr>
+			<?php }
+
+			if ( $google == is_active() ) { ?>
 			<tr>
 				<th><label for="google_sso"><?php esc_html_e( 'Google SSO', 'socialify' ); ?></label></th>
 				<td>
@@ -355,8 +361,10 @@ public static function socialify_user_profile_settings( $user ) {
 					<?php } ?>
 				</td>
 			</tr>
+			<?php } ?>
 		</table>
 		<?php
+		}
 	}
 
 }

From 25b208d7aad252c78ea82a340d279c8bf31296a3 Mon Sep 17 00:00:00 2001
From: Patrick Groot <info@patrickgroot.com>
Date: Tue, 22 Sep 2020 20:59:38 +0200
Subject: [PATCH 4/9] Update socialify.php

---
 socialify.php | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/socialify.php b/socialify.php
index 4c94773..6c5d25e 100644
--- a/socialify.php
+++ b/socialify.php
@@ -329,13 +329,13 @@ public static function socialify_textdomain() {
 	}
 
 	public static function socialify_user_profile_settings( $user ) {
-
-		if ( $facebook || $google == is_active() ) {
+		//var_dump(FacebookLogin::is_active());
+		if ( FacebookLogin::is_active() || GoogleLogin::is_active() == true ) {
 		?>
 		<h3><?php esc_html_e( 'Socialify Settings', 'socialify' ); ?></h3>
 
 		<table class="form-table">
-			<?php if ( $facebook == is_active() ) { ?>
+			<?php if ( FacebookLogin::is_active() == true ) { ?>
 			<tr>
 				<th><label for="facebook_sso"><?php esc_html_e( 'Facebook SSO', 'socialify' ); ?></label></th>
 				<td>
@@ -349,7 +349,7 @@ public static function socialify_user_profile_settings( $user ) {
 			</tr>
 			<?php }
 
-			if ( $google == is_active() ) { ?>
+			if ( GoogleLogin::is_active() == true ) { ?>
 			<tr>
 				<th><label for="google_sso"><?php esc_html_e( 'Google SSO', 'socialify' ); ?></label></th>
 				<td>

From a0ea070148dd04f035c81d81b41ba8d03618ac6e Mon Sep 17 00:00:00 2001
From: Patrick Groot <info@patrickgroot.com>
Date: Tue, 22 Sep 2020 22:03:54 +0200
Subject: [PATCH 5/9] Update socialify.php

---
 socialify.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/socialify.php b/socialify.php
index 6c5d25e..3d3ecd1 100644
--- a/socialify.php
+++ b/socialify.php
@@ -332,7 +332,7 @@ public static function socialify_user_profile_settings( $user ) {
 		//var_dump(FacebookLogin::is_active());
 		if ( FacebookLogin::is_active() || GoogleLogin::is_active() == true ) {
 		?>
-		<h3><?php esc_html_e( 'Socialify Settings', 'socialify' ); ?></h3>
+		<h3><?php esc_html_e( 'Single Sign-On Settings', 'socialify' ); ?></h3>
 
 		<table class="form-table">
 			<?php if ( FacebookLogin::is_active() == true ) { ?>

From 795dcb3874b2017f008383a55142257c6dcf80a5 Mon Sep 17 00:00:00 2001
From: Patrick Groot <info@patrickgroot.com>
Date: Tue, 22 Sep 2020 22:15:22 +0200
Subject: [PATCH 6/9] Update socialify.php

---
 socialify.php | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/socialify.php b/socialify.php
index 3d3ecd1..e81957c 100644
--- a/socialify.php
+++ b/socialify.php
@@ -337,7 +337,7 @@ public static function socialify_user_profile_settings( $user ) {
 		<table class="form-table">
 			<?php if ( FacebookLogin::is_active() == true ) { ?>
 			<tr>
-				<th><label for="facebook_sso"><?php esc_html_e( 'Facebook SSO', 'socialify' ); ?></label></th>
+				<th><label for="facebook_sso"><?php esc_html_e( 'Facebook', 'socialify' ); ?></label></th>
 				<td>
 					<?php $connected == true; 
 					if( $connected == false ) { ?> 
@@ -351,7 +351,7 @@ public static function socialify_user_profile_settings( $user ) {
 
 			if ( GoogleLogin::is_active() == true ) { ?>
 			<tr>
-				<th><label for="google_sso"><?php esc_html_e( 'Google SSO', 'socialify' ); ?></label></th>
+				<th><label for="google_sso"><?php esc_html_e( 'Google', 'socialify' ); ?></label></th>
 				<td>
 					<?php $connected == true;
 					if( $connected == true ) { ?> 

From 709f8caf94882cb164fc9f7eeb92c4f631ba57f3 Mon Sep 17 00:00:00 2001
From: Patrick Groot <info@patrickgroot.com>
Date: Wed, 23 Sep 2020 11:52:02 +0200
Subject: [PATCH 7/9] Added button condition

Also fixed meta_key and removed the unique indentifier from it since its not needed.
---
 includes/FacebookLogin.php |  6 ++++--
 socialify.php              | 25 ++++++++++++++-----------
 2 files changed, 18 insertions(+), 13 deletions(-)

diff --git a/includes/FacebookLogin.php b/includes/FacebookLogin.php
index 3987410..d55fe85 100644
--- a/includes/FacebookLogin.php
+++ b/includes/FacebookLogin.php
@@ -155,7 +155,7 @@ public static function add_setting_id()
             $page = General::$settings_group,
             $section_id = self::$data['settings_section_key'],
             $args = [
-                'name'  => self::$option_name . '[id]',
+                'name'  => self::$option_name,
                 'value' => @get_option(self::$option_name)['id'],
             ]
         );
@@ -189,4 +189,6 @@ public static function add_setting_secret()
     }
 }
 
-FacebookLogin::init();
\ No newline at end of file
+FacebookLogin::init();
+
+?>
\ No newline at end of file
diff --git a/socialify.php b/socialify.php
index e81957c..050e0d3 100644
--- a/socialify.php
+++ b/socialify.php
@@ -207,7 +207,7 @@ public static function user_handler($process_data)
             return false;
         }
 
-        $auth_id_meta_key = 'socialify_' . $process_data['provider'] . '_id_' . $user_data->identifier;
+        $auth_id_meta_key = 'socialify_' . $process_data['provider'] . '_id';
         update_user_meta($user->ID, $auth_id_meta_key, $user_data->identifier);
 
         self::auth_user($user);
@@ -217,7 +217,7 @@ public static function user_handler($process_data)
 
     public static function get_connected_user($identifier = '', $provider = ''){
 
-        $auth_id_meta_key = 'socialify_' . $provider . '_id_' . $identifier;
+        $auth_id_meta_key = 'socialify_' . $provider . '_id';
         $users = get_users(array(
             'meta_key' => $auth_id_meta_key,
             'meta_value' => $identifier,
@@ -329,7 +329,6 @@ public static function socialify_textdomain() {
 	}
 
 	public static function socialify_user_profile_settings( $user ) {
-		//var_dump(FacebookLogin::is_active());
 		if ( FacebookLogin::is_active() || GoogleLogin::is_active() == true ) {
 		?>
 		<h3><?php esc_html_e( 'Single Sign-On Settings', 'socialify' ); ?></h3>
@@ -339,11 +338,13 @@ public static function socialify_user_profile_settings( $user ) {
 			<tr>
 				<th><label for="facebook_sso"><?php esc_html_e( 'Facebook', 'socialify' ); ?></label></th>
 				<td>
-					<?php $connected == true; 
-					if( $connected == false ) { ?> 
-						<button type="button" name="facebook_sso" id="facebook_sso" class="button hide-if-no-js"><?= __('Connect', 'socialify'); ?></button>
-					<?php } else { ?>
+					<?php 
+					$user = get_user_by('id', get_current_user_id());
+					$meta = get_user_meta($user->ID, 'socialify_facebook_id', true);
+					if( is_user_logged_in() && !empty($meta) ) { ?> 
 						<button type="button" name="facebook_sso" id="facebook_sso" class="button hide-if-no-js"><?= __('Disconnect', 'socialify'); ?></button>
+					<?php } else { ?>
+						<button type="button" name="facebook_sso" id="facebook_sso" class="button hide-if-no-js"><?= __('Connect', 'socialify'); ?></button>
 					<?php } ?>
 				</td>
 			</tr>
@@ -353,11 +354,13 @@ public static function socialify_user_profile_settings( $user ) {
 			<tr>
 				<th><label for="google_sso"><?php esc_html_e( 'Google', 'socialify' ); ?></label></th>
 				<td>
-					<?php $connected == true;
-					if( $connected == true ) { ?> 
-						<button type="button" name="google_sso" id="google_sso" class="button hide-if-no-js"><?= __('Connect', 'socialify'); ?></button>
-					<?php } else { ?>
+					<?php 
+					$user = get_user_by('id', get_current_user_id());
+					$meta = get_user_meta($user->ID, 'socialify_google_id', true);
+					if( is_user_logged_in() && !empty($meta) ) { ?> 
 						<button type="button" name="google_sso" id="google_sso"class="button hide-if-no-js"><?= __('Disconnect', 'socialify'); ?></button>
+					<?php } else { ?>
+						<button type="button" name="google_sso" id="google_sso" class="button hide-if-no-js"><?= __('Connect', 'socialify'); ?></button>
 					<?php } ?>
 				</td>
 			</tr>

From 9117ef720e932579effde7310b70303a46795b19 Mon Sep 17 00:00:00 2001
From: Patrick Groot <info@patrickgroot.com>
Date: Wed, 23 Sep 2020 12:04:46 +0200
Subject: [PATCH 8/9] Update FacebookLogin.php

---
 includes/FacebookLogin.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/includes/FacebookLogin.php b/includes/FacebookLogin.php
index d55fe85..3207646 100644
--- a/includes/FacebookLogin.php
+++ b/includes/FacebookLogin.php
@@ -155,7 +155,7 @@ public static function add_setting_id()
             $page = General::$settings_group,
             $section_id = self::$data['settings_section_key'],
             $args = [
-                'name'  => self::$option_name,
+                'name'  => self::$option_name . '[id]',
                 'value' => @get_option(self::$option_name)['id'],
             ]
         );

From 3a5c0a7902dfdf5bc6465a4c7a8bd1e4fdeea4ff Mon Sep 17 00:00:00 2001
From: Patrick Groot <info@patrickgroot.com>
Date: Wed, 23 Sep 2020 23:41:34 +0200
Subject: [PATCH 9/9] Update socialify.php

---
 socialify.php | 30 ++++++++++++++++++------------
 1 file changed, 18 insertions(+), 12 deletions(-)

diff --git a/socialify.php b/socialify.php
index 050e0d3..21b6f75 100644
--- a/socialify.php
+++ b/socialify.php
@@ -169,6 +169,7 @@ public static function start_auth()
 
         catch(\Exception $e){
             error_log('Socialify: Oops, we ran into an issue! ' . $e->getMessage());
+
             wp_redirect(site_url());
             exit;
         }
@@ -241,11 +242,15 @@ public static function add_user($userProfile){
         }
 
         $user_data = [
-            'user_login' => self::generate_new_userlogin(),
+            //'user_login' => self::generate_new_userlogin(),
             'user_pass'  => wp_generate_password( 11, false ),
             'user_email' => sanitize_email($userProfile->email),
         ];
 
+		if( ! empty($userProfile->firstName) && ! empty($userProfile->lastName) ){   
+			$user_data['user_login'] = sanitize_text_field($userProfile->firstName) . ' ' . sanitize_text_field($userProfile->lastName);
+        }
+	
         if( ! empty($userProfile->firstName) ){
             $user_data['first_name'] = sanitize_text_field($userProfile->firstName);
         }
@@ -262,14 +267,14 @@ public static function add_user($userProfile){
             return false;
         }
 
-        if(!$user = get_user_by('id', $user_id)){
+        if( ! $user = get_user_by('id', $user_id)){
             return false;
         }
 
         return $user;
-    }
+	}
 
-    public static function generate_new_userlogin(){
+	public static function generate_new_userlogin(){
         $users_ids  = get_users('fields=ID&number=3&orderby=registered&order=DESC');
         $last_id    = max($users_ids);
         $new_id     = $last_id + 1;
@@ -332,6 +337,7 @@ public static function socialify_user_profile_settings( $user ) {
 		if ( FacebookLogin::is_active() || GoogleLogin::is_active() == true ) {
 		?>
 		<h3><?php esc_html_e( 'Single Sign-On Settings', 'socialify' ); ?></h3>
+		<p><?= __('Connect your account and authorize your desired provider(s) for easy access to this website.', 'socialify'); ?></p>
 
 		<table class="form-table">
 			<?php if ( FacebookLogin::is_active() == true ) { ?>
@@ -340,11 +346,11 @@ public static function socialify_user_profile_settings( $user ) {
 				<td>
 					<?php 
 					$user = get_user_by('id', get_current_user_id());
-					$meta = get_user_meta($user->ID, 'socialify_facebook_id', true);
-					if( is_user_logged_in() && !empty($meta) ) { ?> 
-						<button type="button" name="facebook_sso" id="facebook_sso" class="button hide-if-no-js"><?= __('Disconnect', 'socialify'); ?></button>
+					$meta_f = get_user_meta($user->ID, 'socialify_facebook_id', true);
+					if( is_user_logged_in() && !empty($meta_f) ) { ?> 
+						<button type="button" name="facebook_sso" value="logout" id="facebook_sso" class="button hide-if-no-js"><?= __('Disconnect', 'socialify'); ?></button><p style="display: inline; min-height: 30px; padding:10px; line-height: 2.15384615;"><?= __('your Facebook account.', 'socialify'); ?></p>
 					<?php } else { ?>
-						<button type="button" name="facebook_sso" id="facebook_sso" class="button hide-if-no-js"><?= __('Connect', 'socialify'); ?></button>
+						<button type="button" name="facebook_sso" value="login" id="facebook_sso" class="button hide-if-no-js"><?= __('Connect', 'socialify'); ?></button><p style="display: inline; min-height: 30px; padding:10px; line-height: 2.15384615;"><?= __('your Facebook account.', 'socialify'); ?></p>
 					<?php } ?>
 				</td>
 			</tr>
@@ -356,11 +362,11 @@ public static function socialify_user_profile_settings( $user ) {
 				<td>
 					<?php 
 					$user = get_user_by('id', get_current_user_id());
-					$meta = get_user_meta($user->ID, 'socialify_google_id', true);
-					if( is_user_logged_in() && !empty($meta) ) { ?> 
-						<button type="button" name="google_sso" id="google_sso"class="button hide-if-no-js"><?= __('Disconnect', 'socialify'); ?></button>
+					$meta_g = get_user_meta($user->ID, 'socialify_google_id', true);
+					if( is_user_logged_in() && !empty($meta_g) ) { ?> 
+						<button type="button" name="google_sso" value="logout" id="google_sso"class="button hide-if-no-js"><?= __('Disconnect', 'socialify'); ?></button><p style="display: inline; min-height: 30px; padding:10px; line-height: 2.15384615;"><?= __('your Google account.', 'socialify'); ?></p>
 					<?php } else { ?>
-						<button type="button" name="google_sso" id="google_sso" class="button hide-if-no-js"><?= __('Connect', 'socialify'); ?></button>
+						<button type="button" name="google_sso" value="login" id="google_sso" class="button hide-if-no-js"><?= __('Connect', 'socialify'); ?></button><p style="display: inline; min-height: 30px; padding:10px; line-height: 2.15384615;"><?= __('your Google account.', 'socialify'); ?></p>
 					<?php } ?>
 				</td>
 			</tr>