Last active
October 11, 2021 14:38
-
-
Save VivekSaha/71acd94981079d6e8652332f71fae8f8 to your computer and use it in GitHub Desktop.
Custom Registration Form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Template Name: Custom Registration | |
*/ | |
get_header(); | |
?> | |
<?php | |
global $wpdb; | |
if($_POST['submit']){ | |
$username = $wpdb->escape($_POST['username']); | |
$email = $wpdb->escape($_POST['email']); | |
$password = $wpdb->escape($_POST['password']); | |
$conformpassword = $wpdb->escape($_POST['conformpassword']); | |
$error = array(); | |
if(strpos($username, ' ') !==FALSE){ | |
$error['username_space'] = "Username has Space!!"; | |
} | |
if(empty($username)){ | |
$error['username_empty'] = "Username is empty!!"; | |
} | |
if(username_exists($username)){ | |
$error['username_exists'] = "Username already exists!!"; | |
} | |
if(!is_email($email)){ | |
$error['email'] = "Email is wrong!!"; | |
} | |
if(email_exists($email)){ | |
$error['email_exists'] = "Email already exist!!"; | |
} | |
if(strcmp($password, $conformpassword)!==0){ | |
$error['password_mismatch'] = "Password does not match!!"; | |
} | |
if(count($error) == 0){ | |
wp_create_user( $username, $password, $email); | |
echo "Successfully Created a new User"; | |
exit(); | |
}else{ | |
print_r($error); | |
} | |
} | |
?> | |
<form method="post"> | |
<p> | |
<label for="username">Username: </label> | |
<input type="text" id="username" name="username"> | |
</p> | |
<p> | |
<label for="email">Email: </label> | |
<input type="email" id="email" name="email"> | |
</p> | |
<p> | |
<label for="password">Password: </label> | |
<input type="password" id="password" name="password"> | |
</p> | |
<p> | |
<label for="conformpassword">Conform Password: </label> | |
<input type="password" id="conformpassword" name="conformpassword"> | |
</p> | |
<p> | |
<input type="submit" name="submit"> | |
</p> | |
</form> | |
<?php | |
get_footer(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment