[wp-trac] [WordPress Trac] #39903: is_user_logged_in() true on ajax after cookie has been deleted

WordPress Trac noreply at wordpress.org
Fri Feb 17 20:16:35 UTC 2017


#39903: is_user_logged_in() true on ajax after cookie has been deleted
--------------------------+------------------------------
 Reporter:  esemlabel     |       Owner:
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Users         |     Version:  4.7.2
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:
--------------------------+------------------------------

Comment (by esemlabel):

 Temporary fix for all POST type ajax actions:

 {{{#!php
 <?php
 if( wp_doing_ajax() && !empty( $_POST['action'] ) ){
     add_action( 'wp_ajax_' . $_POST['action'], 'check_session_token_ajax',
 1 );
     add_action( 'wp_ajax_nopriv_' . $_POST['action'],
 'check_session_token_ajax', 1 );
 }

 function check_session_token_ajax(){

     if( is_user_logged_in() && ! wp_get_session_token() ){
         wp_set_current_user( 0 );
     }

 }
 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/39903#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list