WordPress Social Login
Is it possible to sync existing users? (3 posts)

  1. saifur.rahman
    Posted 4 years ago #


    Does the plugin support syncing the existing users of the blog?


  2. shanajk
    Posted 4 years ago #

    I altered my code in /wp-content/plugins/wordpress-social-login/includes/plugin.auth.php and set it to where if the user is logged in it will associate the new network with the current user and add the new user profile link but NOT replace the user avatar or other info.

    The only thing you need to do is add the <?php do_action( 'wordpress_social_login' ); ?> somewhere on a template file to give the logged in user buttons to click.

    under this:

    // try to get user by meta if not
    	if( ! $user_id ){
    		$user_id = (int) wsl_get_user_by_meta( $provider, $hybridauth_user_profile->identifier );

    added code at line 94

    // try to check whether the active session is registered
        if( is_user_logged_in() ) {
            // the user is logged in, set $user_id to their id, don't make a new one
    		$user = get_current_user_id();
    		if( $user != 0 or 1) { // 0 is empty and 1 is the administrator, dont use the Admin account
    			$user_id = $user;
    		} //END if( $user != 0 or 1)
        } //END if( is_user_logged_in() ) {

    under this:

    // not that precise you say... well welcome to my world
    	if( ! $user_age && (int) $hybridauth_user_profile->birthYear ){
    		$user_age = (int) date("Y") - (int) $hybridauth_user_profile->birthYear;

    added code at line 180

    //If user already exists only update the login identifier not the photo, age, gender, etc
        if( is_user_logged_in() ) {
    	update_user_meta ( $user_id, 'user_url'		, $hybridauth_user_profile->profileURL );
    	update_user_meta ( $user_id, $provider		, $hybridauth_user_profile->identifier );
    	update_user_meta ( $user_id, 'wsl_user'		, $provider );
    	} // END if( is_user_logged_in()
    	else {

    under this:

    update_user_meta ( $user_id, 'wsl_user'       , $provider );
    	update_user_meta ( $user_id, 'wsl_user_gender', $hybridauth_user_profile->gender );
    	update_user_meta ( $user_id, 'wsl_user_age'   , $user_age );
    	update_user_meta ( $user_id, 'wsl_user_image' , $hybridauth_user_profile->photoURL );

    added code at line 194
    } // END else if( is_user_logged_in()

    I tried the code edits here first and it didn't work: https://github.com/hybridauth/WordPress-Social-Login/commit/31ce56b4d0cfa3f735d22cfcb80e1c94beac051f

  3. shanajk
    Posted 4 years ago #

    actually i just changed the code at line 180 in my previous post in order to keep from overwriting current data or adding multiple instances of it. This will add new info for each social network if it doesn't already exist while the user is already logged in.

    //If user logged in only add new login identifier, profile url, and provider - not the photo, age, gender, etc but they will be updated if user uses that network to login later
        if( is_user_logged_in() ) {
    		//get the current identifiers
    		$current_identifers = get_user_meta($user_id, $provider);
    		//if identifier does not exist then add it
    		if (!in_array($hybridauth_user_profile->identifier, $current_identifers)) {
    			add_user_meta ( $user_id, $provider, $hybridauth_user_profile->identifier );
    		$current_profileurl = get_user_meta($user_id, 'user_url');
    		if (!in_array($hybridauth_user_profile->profileURL, $current_profileurl)) {
    			add_user_meta ( $user_id, 'user_url', $hybridauth_user_profile->profileURL );
    		$current_wsl_user = get_user_meta($user_id, 'wsl_user');
    		if (!in_array($provider, $current_wsl_user)) {
    			add_user_meta ( $user_id, 'wsl_user', $provider );
    	} // END if( is_user_logged_in()
    	else {

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • WordPress Social Login
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic


No tags yet.