function verify_user_email() {
// Get the verification code from the URL
if ( isset( $_GET[‘verification_code’] ) ) {
$verification_code = sanitize_text_field( $_GET[‘verification_code’] );
// Query users with the matching verification code
$user_query = new WP_User_Query( array( ‘meta_key’ => ’email_verification_code’, ‘meta_value’ => $verification_code ) );
if ( !empty( $user_query->results ) ) {
// If the verification code matches, get the user
$user = $user_query->results[0];
// Delete the verification code from the user meta to mark the user as verified
delete_user_meta( $user->ID, ’email_verification_code’ );
// Show a success message
echo ‘Your email address has been successfully verified!’;
} else {
// If the code is invalid
echo ‘Invalid verification code.’;
}
}
}
add_shortcode( ‘verify_email’, ‘verify_user_email’ );