×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Javascript
Posted by: Daniel Mulder
Added: Jan 15, 2016 10:24 AM
Modified: Jan 15, 2016 10:29 AM
Views: 78
Tags: jquery
This is the jQuery.ajax() call for WordPress to wp-admin/admin-ajax.php to check if user is logged in to WordPress. Needs the PHP snippet to be placed in the functions.php file of the (child) theme. Needs this snippet in place to work: https://tagmycode.com/snippet/4448/wordpress-jquery-ajax-call-to-check-login-status#.VpjJZxXhCUk
  1.  <script type='jquery/jquery.js?ver=1.11.3'></script>
  2.  <script type='jquery-migrate.min.js?ver=1.2.1'></script>
  3.            
  4. <script>
  5.             jQuery(document).ready(function()
  6.             {
  7.                 jQuery.ajax({
  8.                     url : 'http://149.210.200.102/~wptest/wordpress/wp-admin/admin-ajax.php', // "/wp-admin/admin-ajax.php"
  9.                     type : "GET",
  10.                     dataType : "json",
  11.                     cache : false,
  12.                     data : {
  13.                         action : 'check_login'
  14.                     },
  15.                     success : function (json) {
  16.                         if (json.loggedin) {
  17.                             console.log("loggedin");
  18.                         }else{
  19.                             console.log("not loggedin");
  20.                         }
  21.                     }
  22.                 });
  23.             });          
  24. </script>