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
- Access-Control-Allow-Origin error sending a jQuery Post to Google API’s
- Show spinner GIF during an $http request in AngularJS?
- ASP.NET MVC controller actions that return JSON or partial html
- 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.”
- Ajax in a settings page (update_option is undefined)
- redirect out of wp-admin, without losing admin-ajax.php
- How to call a PHP function with Ajax when the user clicks a button
- Ajax for non-logged-in users
- Is there any way of of making an admin-ajax request without the use of die()?
- Ajax request returning full page code
- How-to debug wp_ajax_* hook callback?
- AJAX Implementation
- how to use ajax in plugin admin area?
- edit-comments.php comment_row_actions ajax problem
- jQuery UI Autocomplete showing all results
- Why is my AJAX call not working?
- How to Access custom database content with AJAX onClick refresh of div inside member-only WordPress page?
- Login with cookie but without using WordPress code
- Get wordpress stored cookies for custom login
- Using a nonce in a Custom Login Form
- admin-ajax.php HTTP400: BAD REQUEST – The request could not be processed by the server due to invalid syntax
- WP_Session not acting with AJAX
- Ajaxing in functions.php
- Embedded Twitter feed won’t render nicely when loaded via Ajax
- Enqueue script dinamically
- Most performant way of fetching remote API data?
- Admin-ajax responds with 0 due to empty $_REQUEST
- Using ajax with wordpress
- Using foreach inside an ajax function
- WP_User_Query ignoring ‘meta_query’ arguments
- Why is my staging subdomain not sending wordpress_logged_in cookies?
- Ajax image upload with media_handle_upload and form.js
- Get the_content with ajax
- Caching-Plugins and Ajax-Page-Parts
- Ajax loading duplicate post
- Admin ajax error 400 when passing select value to populate another select
- How do I detect in which page ajax_query_attachments_args is loaded?
- Ajax post returning full html page as response
- Which allowed API hooks work to add wp_ajax action?
- AJAX request randomly stop working and returns error 400
- Sending variable from ajax on form submit
- Ajax store response json in variables
- Performance optimization of tree like structure
- Variable Products Being Added to Cart with AJAX on Shop and Category Pages
- POST Ajax bad request
- Ajax for subscibers not working
- Is it possible to determine whether a page is a page template by page_id in ajax call?
- 200 return code on ‘POST /wp-admin/admin-ajax.php’ while NOT logged in
- i’m trying to get all my media query attachments via ajax in wordpress
- Distinguish between 2 instances of admin-ajax.php
- How to update post with Ajax (no plugin)
- Next Ajax call doesn’t work
- Ajax page load without reload
- need a confirmation text to appear on email submission
- Is there something I need to know in order to use WordPress on foreign (Swedish) TLDs?
- WordPress Ajax Page Load to skip embedded iframe
- edit user input data contact form 7
- Set cors header for ajax requests
- Simple AJAX code that refreshes every x seconds?
- Search function – problem with whole words
- jQuery ajax method does not return data
- Ajax is not defined
- The same session information for peer users on two different WordPress servers
- Get posts by category via ajax
- Download doccument on server rather than clients browser
- Load oEmbed iframe within ajax call
- WordPress 4.9.6 – IncludeMe & getAjax GET using wrong URL
- Create secondary Archive page format?
- Get post details with pure javascript ajax
- WorddPress website admin part not working correctly – I think ajax/json issue
- Ajax Security regarding user priviliges and nonces
- Use ajax without a plugin?
- Weird admin-ajax.php problem
- Ajax contact form returnig 0
- Know which script/page is being called by ajax call
- Can’t update WP Editor after Ajax
- Posting to loop.php file
- Running js in html code with same content
- How to get current_user_id from wordpress in node js?
- AJAX call not initializing for non-admins in WordPress