I add one function wp_set_current_user for setting up current user.
add_action( 'wp_ajax_facebook_login', 'facebook_ajax_login_or_register' );
add_action( 'wp_ajax_nopriv_facebook_login', 'facebook_ajax_login_or_register' );
function facebook_ajax_login_or_register(){
$uid = sanitize_text_field( $_POST['uid'] );
$args = array(
'meta_key' => 'fbuid',
'meta_value' => $uid,
'meta_compare' => '=',
);
$fb_user = get_users($args);
$current_user_id = $fb_user[0];
wp_set_current_user($current_user_id);//Set current user
wp_set_auth_cookie( $current_user_id, true );
$response[success] = true;
echo json_encode($response);
die();
}
I’m not tested this so let me know if still you facing same issue.
Related Posts:
- WordPress Ajax Login without page reload
- Why a strange discrepency between get_current_user_id() when using AJAX versus output of document.cookie?
- Ajax login fails: script sets cookies, but is_user_logged_in() returns false
- WordPress AJAX Login Screen
- Detecting post type within init action
- WordPress Nonce Issue for Ajax Login and Logout
- How can I automatically login using a URL?
- how to use reCaptcha v3 in wordpress custom login form?
- Is it safe to manually sign a user in using AJAX?
- Woocommerce Ajax Add cart not working
- SSO autologin WordPress + Ajax
- How can I set cookies on both secure and non-secure origins at the same time?
- Ajax login without redirect/reload
- Interim-Login form on frontend
- Custom Login with Ajax not working with IE
- jQuery.post returns 0
- WordPress custom ajax login not working on mobile browsers
- Caching for logged in user and Ajax update
- PHP cookie not set within AJAX call
- I’m trying to register with AJAX
- Nonce verification problem when logging in after a logout
- PHP “php://input” vs $_POST
- Google Maps API throws “Uncaught ReferenceError: google is not defined” only when using AJAX
- Access-Control-Allow-Origin error sending a jQuery Post to Google API’s
- Access-Control-Allow-Origin error sending a jQuery Post to Google API’s
- How to solve the error “SCRIPT7002: XMLHttpRequest: Network Error 0x80070005, Access is denied.” in IE
- Show spinner GIF during an $http request in AngularJS?
- Refresh HTML Page in Browser Automatically on Timer – Every 15 Min
- JavaScript implementation of Gzip
- jQuery: Performing synchronous AJAX requests
- ASP.NET MVC controller actions that return JSON or partial html
- jQuery’s .on() method combined with the submit event
- Ajax takes 10x as long as it should/could
- How to check if I am in admin-ajax.php?
- Can’t log in: “ERROR: Cookies are blocked or not supported by your browser. You must enable cookies to use WordPress.”
- Best way to end WordPress ajax request and why?
- How to load wp_editor() through AJAX/jQuery
- Login page ERROR: Cookies are blocked due to unexpected output
- How to cache json with wp-super cache
- Load minimum WordPress environment
- Why use wp_send_json() over echo json_encode()?
- Why use admin-ajax.php and how does it work?
- How to get a unique nonce for each Ajax request?
- Open a Thickbox with content trough AJAX
- Initialize TinyMCE editor / visual editor after AJAX insert
- Removing username from the ‘wordpress_logged_in’ cookie
- Why not register shortcodes if is_admin dashboard?
- WordPress AJAX with Axios
- Why is die() used at the end of function that handles an Ajax request?
- Why might a plugin’s ‘do_shortcode’ not work in an AJAX request?
- Making my AJAX powered WordPress Crawlable
- Is there a JavaScript API? How to access public and private data in JS?
- Get Previous & Next posts by Post ID
- failed to load wp-admin/admin-ajax.php
- Using Backbone with the WordPress AJAX API
- Using Ajax with a Class file
- Ajax in a settings page (update_option is undefined)
- How to pass data parameter to ajax action function handler
- WordPress Ajax Data Security
- Displaying PHP Errors from admin-ajax.php
- Adding “Remember Me” in custom login
- gettext does not translate when called in ajax
- Execute one AJAX request after another AJAX request finished
- WP-AJAX vs WP REST API: What to use for requests to the website from outside?
- Ajax and autocomplete
- How can I make an Ajax login form work with FORCE_SSL_ADMIN enabled?
- How to add to cart via AJAX Woocommerce [closed]
- Nonces and Cache
- SSL breaks customizer: page isn’t returned from ajax
- Why is a 500 error generated by admin-ajax.php not going into the Apache error log?
- Are ‘wp_ajax’ and ‘wp_ajax_nopriv’ exclusive to authenticated and non-authenticated users?
- How to HTML5 FormData Ajax
- admin-ajax.php vs Custom Page Template for Ajax Requests
- How to override WP_DEBUG for Ajax responses?
- Stop admin-ajax?
- redirect out of wp-admin, without losing admin-ajax.php
- Call to undefined function add_action()
- Is it safe to assume that a nonce may be validated more than once?
- How build a custom login/register form with error handling?
- Including WordPress in RESTful API
- Multiple ajax nonce requests
- Get posts with ajax
- admin-ajax.php doesn’t work when using POST data and Axios
- How to call a PHP function with Ajax when the user clicks a button
- REST API endpoint for elasticpress autosuggest
- Ajax for non-logged-in users
- Contact Form 7 Custom Post Action
- Custom Form with Ajax
- How to process ajax requests correctly using ajax plugins
- ajax – why multiple calls to wp_create_nonce() return same value?
- Update user meta using with ajax
- Registering AJAX callback function that is part of a class without instantiating the class in function.php
- WordPress function that makes HTML safe to be sent via AJAX request
- How do I hook an Ajax request into a PHP callback?
- AJAX request on the frontend always returns 0 if user is not admin
- admin-ajax.php returns 0. How do I debug it and fix it?
- Ajax requests without JQuery
- Admin Notification after save_post, when ajax saving in gutenberg
- How to properly use wp.ajax.post?
- Load tinyMCE / wp_editor() via AJAX [duplicate]