I have my "own" registration system and I want users to verify their email. Since there is no builtin function for that I use the "get_password_reset_key( $user )" function since it will generate a key which I can verify with "check_password_reset_key( $_REQUEST['key'], $_REQUEST['login'] );".
It works great, but it would be nice to have the same functions with the appropriate naming. After all we all want to fight spam and requesting users to verify their email is important.
So basically this is what I mean:
get_email_verification_key( $user_data );
$message = __('This is an email verification for the following account:') . "\r\n\r\n";
$message .= network_home_url( '/' ) . "\r\n\r\n";
$message .= sprintf(__('Username: %s'), $user_login) . "\r\n\r\n";
$message .= __('If email was verified already, just ignore this email and nothing will happen.') . "\r\n\r\n";
$message .= __('To verify your email, visit the following address:') . "\r\n\r\n";
$message .= '<' . network_site_url("email-verification?action=ve&key=$key&login=" . rawurlencode($user_login), 'login') . ">\r\n";
$blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
$title = sprintf( __('[%s] Email Verification'), $blogname );
/**
* Filter the subject of the email verification email.
* @param string $title Default email title.
* @param string $user_login The username for the user.
* @param WP_User $user_data WP_User object.
*/
$title = apply_filters( 'retrieve_email_title', $title, $user_login, $user_data );
/**
* Filter the message body of the email verification mail.
* @param string $message Default mail message.
* @param string $key The activation key.
* @param string $user_login The username for the user.
* @param WP_User $user_data WP_User object.
*/
$message = apply_filters( 'retrieve_email_message', $message, $key, $user_login, $user_data );
if ( $message && !wp_mail( $user_email, wp_specialchars_decode( $title ), $message ) )
{
$_SESSION["home_error"] = "Verification email could not be sent";
exit;
}
And to verify simply do this:
$user = check_email_verification_key( $_REQUEST['key'], $_REQUEST['login'] );