×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: PHP
Posted by: Daniel Mulder
Added: Jan 15, 2016 10:28 AM
Views: 16
Tags: wordpress
Place this snippet in the functions.php of the (child) theme and use ajax call from browser side javascipt / jQuery ajax call.
  1. /**
  2.  * Daniel Mulder:
  3.  * Call to get login status from javscript in browser
  4.  * @return json string with boolean.
  5.  */
  6. function check_login() {
  7.     $return['loggedin'] = false;  
  8.     if ( is_user_logged_in() ) {
  9.         $return['loggedin'] = true;    
  10.     }
  11.     echo json_encode($return);
  12.     die();
  13. }
  14. add_action('wp_ajax_check_login', 'check_login');
  15. add_action('wp_ajax_nopriv_check_login', 'check_login');