Last active
March 18, 2021 18:01
-
-
Save banagale/c3735ac99607ad2893b95132ab13f306 to your computer and use it in GitHub Desktop.
Output WordPress user authentication status to console
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function display_wordpress_user_auth() | |
{ ?> | |
<script> | |
<?php | |
$current_user = wp_get_current_user(); | |
if (isset($current_user)) { | |
if ($current_user->ID === 0) { | |
echo 'console.log(\'User is anonymous\');'; | |
} else { | |
echo 'const wpUserEmail =\'' . $current_user->user_email . '\';' . PHP_EOL; | |
echo 'console.log(\'User is authenticated as: \', wpUserEmail);'; | |
} | |
} | |
?> | |
</script> | |
<?php | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated to PSR-12