Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

Custom Connect to Facebook, problem logging in/logging out

The tutorial from the link I provided was destroying the facebook session after login in and creating a new account for some reason. I just had to remove $facebook->destroySession(); from both parts and now everything is working as intended.

Here is the code from the tutorial with both lines commented out.

if ($fbuser) {


    $fb_registerpage_name = __('Facebook Register', 'bloora');
    $fbpage = get_page_by_title( $fb_registerpage_name );

    if(isset($user_profile['email'])){
        $user_name = $user_profile['email'];
        $user_email = $user_profile['email'];
        $user_id = username_exists( $user_name );
        if ( !$user_id and email_exists($user_email) == false ) {
                $random_password = wp_generate_password( $length=12, $include_standard_special_chars=false );
                $user_id = wp_create_user( $user_name, $random_password, $user_email ); 
                wp_set_current_user( $user_id );
                wp_set_auth_cookie( $user_id );
               // $facebook->destroySession(); THIS HAS TO BE REMOVED

        } else {
                $random_password = __('User already exists.  Password inherited.');

                wp_set_current_user( $user_id );
                wp_set_auth_cookie( $user_id );
               // $facebook->destroySession(); THIS HAS TO BE REMOVED!
        }
    }else{

        if(!is_admin() && isset($_POST) && count($_POST) > 0){

            if($fbpage){

                echo '<script>if(window.location.href != "'.get_permalink($fbpage->ID).'"){ window.location.href = "'.get_permalink($fbpage->ID).'"; }</script>';
            }else{
                // Create post object
                $my_post = array(
                  'post_title'    => $fb_registerpage_name,
                  'post_content'  => 'This is my post.',
                  'post_status'   => 'publish',
                  'post_type'   => 'page',
                  'post_author'   => 1
                );

                // Insert the post into the database
                $fbpage = wp_insert_post( $my_post );
                echo '<script>if(window.location.href != "'.get_permalink($fbpage->ID).'"){ window.location.href = "'.get_permalink($fbpage->ID).'"; }</script>';

            }
        }
    }
}

Related Posts:

  1. How reduce wordpress login session timeout time?
  2. how to logout user on browser tab or window closes
  3. Session Experies and Get Logged Out Within Few Minutes
  4. Preventing session timeout
  5. Removing username from the ‘wordpress_logged_in’ cookie
  6. Disable WordPress 3.6 idle logout / login modal window / session expiration
  7. How to pass users back and forth using session data?
  8. How to fake a WordPress login?
  9. Does wp_logout_url() destroy a session? (Logging out question)
  10. share login/logout sessions across two installs?
  11. How can I test the login for an expired session?
  12. How do I extend auto logout on idle OR redirect inline popup
  13. How long do users stay logged in if they DON’T check remember me?
  14. How to get login data (session) outside WordPress?
  15. Is it possible a one click user registration with Facebook or Twitter (or other Social Networks)?
  16. How can I test the login for an expired session?
  17. How does WordPress handle sessions?
  18. Preexisting login to change to logout link in sub menu
  19. Force users to register in order to view website [duplicate]
  20. WordPress as webapp login session
  21. What would be the best way to implement Magic Link logins in WordPress?
  22. Share WordPress login info with other PHP app
  23. Facebook login for private group members
  24. WordPress error on log out ‘Not Permitted’ and can’t log out
  25. Best option to implement external register/login to WP from self-made API
  26. Facebook and WordPress
  27. Add logout link when logged in, make it disappear when logged out?
  28. Lock out all WordPress Administrators except two specific users
  29. How to remove ‘wordpress…’ text from page titles in tabs
  30. how do i change my website facebook login button to another text immediately user login? [closed]
  31. One time login on 2 different WordPress sites
  32. Membership Plugin with Facebook integration [closed]
  33. Get WordPress login functions without printing anything
  34. add class to element if user is not logged in [closed]
  35. End session screen not close automatically after login
  36. Problem with is_user_logged_in() function in some pages
  37. wordpress login loop and session problem
  38. Get WordPress logged in username from root domain when WP is installed in a subfolder
  39. Set logged in user based on API response
  40. Why deleting/removing cookies in WordPress does not log me out from admin?
  41. How to use google api for wordpress login
  42. User not logged first time I open the homepage
  43. wp_logout logging everyone out instead of just the user that clicked the logout link!
  44. How to limit user to login only once per session
  45. how to manage Session in WordPress using custom login?
  46. Inconsistent login state
  47. Can i hide a dynamically created div to logged out users?
  48. Login and register by API
  49. How to use WordPress REST API to login a user with dart/flutter?
  50. In Django, how do I know the currently logged-in user?
  51. Face recognition via facebook API
  52. Can I programmatically login a user without a password?
  53. Can’t log in: “ERROR: Cookies are blocked or not supported by your browser. You must enable cookies to use WordPress.”
  54. Is there any way to rename or hide wp-login.php?
  55. How to login with email only no username?
  56. How can I redirect user after entering wrong password?
  57. Increase of failed login attempts, brute force attacks? [closed]
  58. Login page ERROR: Cookies are blocked due to unexpected output
  59. Separate registration and login for different roles
  60. SSO / authentication integration with external ‘directory service’
  61. How to prefill WordPress registration with social details
  62. Check for correct username on custom login form
  63. Disallow user from editing their own profile information
  64. I can’t access my site via wp-admin
  65. ‘Password field is empty’ error when using autofill in Chrome
  66. How to show ‘login error’ and ‘lost password’ on my template page?
  67. What is $interim_login?
  68. Custom login form
  69. How to prefill the username/password fields on the login page
  70. wp_signon returns user, but the user is not logged in
  71. Adding extra authentication field in login page
  72. Destroy user sessions based on user ID
  73. Prevent wp_login_form() from redirecting to wp-admin when there are errors
  74. Redirect user using the ‘wp_login_failed’ action hook if the error is ’empty_username’ or ’empty_password’
  75. wp_signon() does not authenticate user guidance needed
  76. What exactly is ReAuth?
  77. What are the differences between wp_users and wp_usermeta tables?
  78. Login members using web services
  79. Make my wordpress blog remember my login “forever”
  80. How to check in timber if user is loggedin?
  81. How do I change the language of only the login page?
  82. How to change the default logout link on WordPress Admin
  83. Stop WordPress from logging me out (need to keep me logged in)
  84. Woocommerce registration page [closed]
  85. How to disable autocomplete on the wp-login.php page
  86. Share login data/cookies between multiple installations
  87. Synchronize WordPress user accounts across multiple domains and installations without using WordPress MU
  88. How do I change the logo on the login page?
  89. Allow up to 5 Concurrent Login Sessions
  90. Why does WordPress hide the reset password key from the URL?
  91. Is it possible to sign in with user_email in WordPress?
  92. How to use current_user_can()?
  93. Avoid to load default WP styles in login screen
  94. WordPress registration message
  95. how to display the wordpress login and register forms on a page?
  96. How can I send a welcome email to a user AFTER they login for the first time?
  97. Can not login with correct username and password
  98. Website Visible only to Registered users
  99. How can i increase the login expiration length?
  100. How do I use add_action from a class method?
Categories login Tags api, facebook, login, logout, session
array of objects to do_action, callback gets singular object?
I am trying to use the Theme Customization API but I keep getting an error

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Post Navigation Elementor
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • WPFacet multiple loop displaying duplicate content
  • Get the name of the template/*html file used
  • Fix: WordPress.DB.PreparedSQL.NotPrepared Plugin Check (PCP)
  • Removing unnecessary CSS and JS code from wp_head()
  • hexagonal image gallery. Am I on the right track? [closed]
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress