Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Email conditional WordPress

  • SOLVED

Hello I want a simple conditional , for registered users .They login to my site with twitter sign in and I have their info ( biography , profile name , avatar , and their twitter link ) but I also want email . Screenshot : http://easycaptures.com/fs/uploaded/713/4999879953.png


So with less word I want something like this , for users without email filled I want to ask email from them

I think this can help


<?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";
?>

Answers (4)

2014-04-23

Arnav Joy answers:

try this

<?php

global $current_user;

$email = $current_user->user_email;

$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";

?>


Magas ramo comments:

ooo Great very close to what I want

how I can replace

That E-mail doesn't belong to any registered users on this site

with


You are connected via Twitter.
Please complete the registeration.
<?php echo do_shortcode("[userpro template=edit type=edit no_style=true layout=true no_header=true]"); ?>


Arnav Joy comments:

<?php



global $current_user;



$email = $current_user->user_email;



$exists = email_exists($email);



if ( $exists )



echo "That E-mail is registered to user number " . $exists;



else{


echo "You are connected via Twitter.<br>";


echo "Please complete the registeration. ";

echo do_shortcode("[userpro template=edit type=edit no_style=true layout=true no_header=true]");
}



?>


Magas ramo comments:

Great ...you find the solution to my problem

the only problem is that I have to reload the page to show them sucsess message ( That E-mail is registered to user number " . $exists )


Arnav Joy comments:

yes , this plugin not reloads the page after login , this can be done but needs custom work in plugin files .

2014-04-23

Kyle answers:

This looks like it should work, where are you having issues?


Kyle comments:

Oh, I see, what plugin are you using for the twitter sign in?


Magas ramo comments:

userpro


Kyle comments:

The docs http://userproplugin.com/userpro/docs/#twitter don't seem to say anything about altering what info gets pulled from Twitter when they register. Is there anything in your install that you can see for altering the info?

What you could do is setup a redirect, that when a user is logged in, checks if they have an email. Then if their email field is empty, redirects to a page with a form to update their email address. Would that work?

2014-04-23

Francisco Javier Carazo Gil answers:

You can use it:

function email_exists($email){
$blogusers = get_users('search=$email');
if(count($blogusers) == 0)
return false;
else
return true;
}


Francisco Javier Carazo Gil comments:

Oh this functions already exists :s https://codex.wordpress.org/Function_Reference/email_exists

2014-04-23

Hariprasad Vijayan answers:

Hi,

Try this

if ( is_user_logged_in() ) {
global $current_user;
get_currentuserinfo();
$exists = $current_user->user_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";
}
}

Let me know if you need help.