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. Login page ERROR: Cookies are blocked due to unexpected output
  50. Separate registration and login for different roles
  51. What is $interim_login?
  52. Login members using web services
  53. How to change the default logout link on WordPress Admin
  54. Synchronize WordPress user accounts across multiple domains and installations without using WordPress MU
  55. How do I change the logo on the login page?
  56. Allow up to 5 Concurrent Login Sessions
  57. Why does WordPress hide the reset password key from the URL?
  58. Clearing cookie on logout and session expiration
  59. Receiving “This content cannot be displayed in a frame” error on login page
  60. Getting “Cookies are blocked or not supported by your browser” on login page
  61. wp-login.php redirecting to HTTPS
  62. wp_login action hook not working
  63. Make wordpress admin failed login attempt return 401
  64. Positioning the “Lost your password?” and “← Back to Site”
  65. Warning: Cannot modify header information – headers already sent
  66. Change to nofollow tag in wp-login.php
  67. Validate Custom Login field
  68. Redirect user after logout
  69. How can I allow access to two user accounts using one login?
  70. 2 wordpress blogs with 1 users table and 1 login
  71. How can i add validation to this login form with out it redirecting to the wp-login.php page
  72. Bootstrap Modal as login page
  73. Custom login page always redirecting to wp-login.php
  74. WordPress custom login page
  75. auto login after registeration for wp-members plugin
  76. Passing username to login screen
  77. Sniffing wordpress user’s credentials
  78. How to Get Logged-in to “Remote WP Site” from my local script (in Same Browser)?
  79. v5.6.2 User cannot stay logged in – wordpress_test cookie placed but not auth cookies
  80. How to set JWT token with PHP on successful login?
  81. wp-admin redirects to subdirectory after moving installation to subdirectory
  82. Expired session error (admin) when I try to make a call to WooCommerce api [closed]
  83. WordPress c-panel login error [closed]
  84. Secure login on wordpress [closed]
  85. How can I password protect a WordPress site without requiring users to log in?
  86. I cannot login and am getting this error message. .
  87. Can I Get User ID at Login?
  88. Reset Password Limit not working
  89. Problem in auto login after registration
  90. How to invalidate `password reset key` after being used
  91. Special link for no automatic login (no username and no password)
  92. Global login to password protected pages
  93. Making sure two different wordpress website has auto login
  94. Improvements to “limit login attempts” plugin
  95. loging to Admin page not working at all
  96. Can’t login through wp-login.php on fresh installation
  97. Authenticate return value
  98. Using wp_login_form passowrd as undefined
  99. Redirect non-members to about/intro page
  100. Log in a user upon password reset?
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
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 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