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
- jQuery’s .on() method combined with the submit event
- Why is die() used at the end of function that handles an Ajax request?
- Making my AJAX powered WordPress Crawlable
- Using Backbone with the WordPress AJAX API
- WordPress Ajax Data Security
- How to add to cart via AJAX Woocommerce [closed]
- How to override WP_DEBUG for Ajax responses?
- Call to undefined function add_action()
- Registering AJAX callback function that is part of a class without instantiating the class in function.php
- admin-ajax.php vs .load() in WordPress
- Refused to execute script from ‘***’ because its MIME type (‘text/html’) is not executable, and strict MIME type checking is enabled
- AJAX call using admin-ajax URL is returning 400 bad request
- Ajax response is always 0
- Ajax with OOP doesn’t work
- Error 400 bad request using admin-ajax.php
- Setting TinyMCE Content in wp_editor
- Ajax is not working for logged out users
- WP Ajax Action Not Picking Up Query String Parameter
- How to use wp_send_json_error?
- Ajax Redirect role = ‘Editor’ to their Dashboard after register
- Form data is empty while posting form through ajax using jquery in WordPress
- Logins through alias
- How do I check if AJAX nonces are implemented correctly?
- Can I fire an add_action hook inside of a function that recieves data via wp_ajax?
- Force redirect not logged in user to (wp-login.php or wp-admin) for specific page
- How to insert a record by clicking on the link using AJAX
- Updating a checkbox value to database for specific row in table
- WordPress Ajax Not Working ( Custom Admin page)
- Load JavaScript from a post that’s loading into Fancybox via ajax
- Gravity form Load By Ajax Cannot Submit – Error 400
- How to save generated JWT token to cookies on login?
- How get child posts in custom post type by ajax?
- contact form ajax empty response error message
- Cache wp-json/posts without a plugin?
- What is the best way to do MyAjax error and success handling?
- Gravity Forms closes my popup on Validation Error [closed]
- How to handle cookies from a WordPress plugin on a cached page?
- Attach time/date stamp on add_post_meta
- Uncaught ReferenceError: the_ajax_script is not defined . How is this not defined?
- infinite scroll not working when logged out
- Right way to include blog-header.php?
- I can’t get a return value from Ajax
- WordPress AJAX return 0 – My case
- Creating an auto result search bar
- update_option is not saving an array, but saving the string ‘Array’
- Ajax call in wordpress not working for subscriber user
- Upload data from weather station to WordPress Website
- Ajax call in WordPress – unable to display the data on the page
- How to reuse get_template_part() containing a simple loop to work with AJAX correctly?
- Need help with ajax
- Using nonce when loading posts with AJAX
- What WP-API authentication method should I use to interact with anonymous / not-logged visitors?
- How to call ajax in plugin file
- Tabbed feeds with ajax vs. without on homepage [closed]
- Unable to execute Ajax request, status code 400
- javascript onClick update user_meta from jquery.ajax
- How to ignore WP_ERROR caused by “get_the_excerpt” method in an AJAX call?
- WP_Query is not received in Ajax
- How do I mitigate replay attacks when talking about actions that shouldn’t happen twice?
- Login issue with subdomain installs
- Updating Jquery object with newly created elements after AJAX call
- Not getting ajax success response on insert/update row to database
- Wp admin ajax load more
- Ajax call from Plugin using Class
- enqueue style using admin-ajax.php
- How to safely pass post_id and user_id via AJAX to the backend (prevent user from changing it via JS)?
- Can’t get next post info with ajax
- How to inject data content from external json into a modal, using UIkit?
- Update user meta via ajax from frontend, saving issue
- How to get the admin page slug using wp_loaded hook?
- Edit user meta on front-end via AJAX
- How to paginate Ajax result
- Cannot access class properties from ajax call in wpordrpess
- why is my main.js not loading?
- Enqueue dynamically generated javascript
- First time doing Ajax with WP, how to do it?
- Tie the sending of an ajax request to WordPress hooks
- AJAX: admin-ajax.php is adding extra content to my script’s response – how to exclude header, footer, etc.?
- $wpdb Ajax not redirecting to main page
- how reduce fetch/XHR response time
- Custom WP rest api endpoint only working on non https?