More precisely questions : How to override email_exists
via get_user_by
?
I have chosen to render unusable/unreadable email adresses from database.
I added a few elements(chars) to email address just after sending email to admin and user (user registration), and then I must remove these added elements to verify if email exists or display on user account or use for mailing list.
To decrypt the email I must use substr
whith the value associated to $email
field of get_user_by
to remove elements added before.
I read that email_exists
use get_user_by
which is a pluggable function. But I don't know how to use the result of get_user_by
inside email_exists
.
Is it possible ? How should I do ?
function get_user_by( $field, $db_email ) {
$field = 'email';
//function to decrypt my email from database
$ex = preg_split('\'@\'', $nr , -1);
$dem = substr(substr($ex[0],2),0,-2);
$rdem = substr($dem,0,2).substr($dem,2+1,strlen($dem)-2);
$db_email = $rdem. '@' .$ex[1];
$userdata = WP_User::get_data_by( 'email', $db_email );
if ( ! $userdata ) {
return false;
}
$user = new WP_User;
$user->init( $userdata );
return $user;
}
function email_exists( $email ) {
$user = get_user_by( $field, $db_email );
if ( $user ) {
$user_id = $user->ID;
} else {
$user_id = false;
}
return apply_filters( 'email_exists', $user_id, $email );
}
if (email_exists($email)){
lq_errors()->add("emailexists","This email address already exist");
}