Check if Wordpress User exists by email
For the life of me I cant get this to work (default example from WP Codex). I created a php file with this code and dropped it in my theme folder, when I access the file on the web I get a blank page, nada -- am I missing something, do i have to put this someplace else? any help is greatly appreciated.
<?php $email = '[email protected]'; $exists = email_exists($email); if ( $exists ) echo "That E-mail is registered to user number " . $exists; else echo "That E-mail doesn't belong to any registered users on this site"; ?> Table of Contents
2 Answers
simple answer, If that is the template page, than use this:
<?php $email = '[email protected]'; $exists = email_exists($email); if ( $exists ) echo "That E-mail is registered to user number "; else echo "That E-mail doesn't belong to any registered users on this site"; ?> and ensure you have correct opening and closing php tags.
But if are from other than tempalte page then use this:
π For more insights, check out this resource.
<?php require_once("../../../../wp-load.php"); //ADD THIS $email = '[email protected]'; $exists = email_exists($email); if ( $exists ) echo "That E-mail is registered to user number "; else echo "That E-mail doesn't belong to any registered users on this site"; ?> Add or Remove ../ in the require_once("../../../../wp-load.php") as per the page location. This will surely help you.
Try to add wp-load.php in your file with right path.
π Discover more in this in-depth guide.
<?php require_once("../../../wp-load.php"); //ADD THIS $email = '[email protected]'; $exists = email_exists($email); if ( $exists ) echo "That E-mail is registered to user number " . $exists; else echo "That E-mail doesn't belong to any registered users on this site"; ?>