Skip to content

Instantly share code, notes, and snippets.

@accessomnath
Last active November 18, 2016 11:47
Show Gist options
  • Save accessomnath/6644edc34ce037bc10acbae29b73eba7 to your computer and use it in GitHub Desktop.
Save accessomnath/6644edc34ce037bc10acbae29b73eba7 to your computer and use it in GitHub Desktop.
<?php
/**
* Template Name: Register
* Created by PhpStorm.
* User:Somnath
* Date: 9/29/2016
* Time: 9:59 PM
*/
get_header();
$x=$_GET['x'];
?>
<div class="container">
<div class="row">
<div class="custom-margin">
<div class="col-md-6 panel panel-danger" style="margin-top: 20px;">
<div class="panel-heading">
<h3 class="panel-title">Registration Here</h3>
</div>
<div class="panel-body">
<form id="signup-form" method="post" class="s-form wow zoomInUp" data-wow-delay="0.5s">
<div class="form-group col-md-12">
<label class="control-label" for="name">Enter Name: </label>
<input type="text" placeholder="FULL NAME" value="" name="name" id="name" class="form-control" />
</div>
<div class="form-group col-md-12">
<label class=" control-label" for="name">Email Address: </label>
<input type="email" placeholder="EMAIL ID" value="" name="email" id="email" class="form-control" />
</div>
<div class="form-group col-md-12">
<label class="control-label" for="name">Phone Number: </label>
<input type="number" placeholder="PHONE NO" value="" name="phone" id="phone" class="form-control" />
</div>
<div class="form-group col-md-12">
<label class=" control-label" for="name">Enter Password:</label>
<input type="password" placeholder="PASSWORD" value="" name="password" id="password" class="form-control" />
</div>
<input type="button" name="btn_submit" class="btn btn-danger" id="btn_submit1" value="Submit" style="float:right;margin-right: 17px;background-color:#ee8323;border-color:#ee8323;border-radius:0px;">
</form>
</div>
</div>
<div class="col-md-6 panel panel-danger" style=" margin-top: 20px;">
<div class="panel-heading">
<h3 class="panel-title">Login Here</h3>
</div>
<p style="color:red;margin-left:10px;margin-top:10px"><?php echo $x; ?><p>
<form id="login" class="s-form wow zoomInUp" name="form" action="<?php echo home_url(); ?>/login/" method="post">
<div class="form-group col-md-12">
<label class="control-label" for="name">Enter Email: </label>
<input type="text" placeholder="Email Address" value="" name="username" id="username" class="form-control" required/>
</div>
<div class="form-group col-md-12">
<label class="control-label" for="name">Enter Password: </label>
<input type="password" placeholder="Password" value="" name="password" id="password" class="form-control" required/>
</div>
<input id="submit" class="btn btn btn-danger" type="submit" name="submit" value="Login" style="float:right;margin-right: 17px;margin-bottom: 10px;background-color:#ee8323;border-color:#ee8323;border-radius:0px;">
</form>
<!-- <label for="chk" style="color:#026466">-->
<p style="float:right;margin-right:10px;"><input type="checkbox" id="chk1" style="height:12px;margin-top:10px;width:20px;"><span style="margin-left:5px;">Forgot Password?</span></p>
<div class="col-md-12" id="list1">
<form name="lostpasswordform" id="lostpasswordform" action="<?php echo wp_lostpassword_url(); ?>" method="post">
<p>
<label class="control-label" for="name" style="color:#888;">Username or E-mail:<br> </label>
<input type="text" name="user_login" id="user_login" class="form-control" value="" placeholder="Username or E-mail" required>
</p>
<input type="hidden" name="redirect_to" value="<?php echo $redirect ?>">
<input type="submit" name="wp-submit" id="wp-submit" class="btn btn btn-danger" value="Get New Password" style="float:right;margin-bottom: 10px;background-color:#ee8323;border-color:#ee8323;border-radius:0px;">
</form>
</div>
</div>
</div>
</div>
</div>
<?php get_footer(); ?>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(function () {
// Get the form fields and hidden div
var checkbox = $("#chk1");
var hidden = $("#list1");
hidden.hide();
checkbox.change(function () {
if (checkbox.is(':checked')) {
hidden.show();
} else {
hidden.hide();
// $("#list").val("");
}
});
});
</script>
<script type="text/javascript">
var ajaxurl = "<?php echo admin_url('admin-ajax.php'); ?>";
</script>
<script type="text/javascript">
$(function() {
$('#btn_submit1').click(function() {
var name = $('#name').val();
var email = $('#email').val();
var phone = $('#phone').val();
var password = $('#password').val();
if (name == "") {
swal(" Full Name is a required field");
return false;
}
if (email == "") {
swal("Email is a required field");
return false;
}
if (phone == "") {
swal("Phone is a required field");
return false;
}
if (password == "") {
swal("Password is a required field");
return false;
}
var data = {
'action': 'create_user',
'name': name,
'email': email,
'phone': phone,
'password': password
};
$.ajax({
type: "POST",
url: ajaxurl,
data: data,
success: function (response) {
swal(response);
$("#signup-form")[0].reset();
},
error: function (response) {
swal(response);
$("#signup-form")[0].reset()
},
});
});
});
</script>
==============================================
adn in the function .php add snippet
==============================================
/*add action for member registration.............start..............*/
add_action( 'wp_ajax_create_user', 'it_create_user' );
add_action( 'wp_ajax_nopriv_create_user', 'it_create_user' );
function it_create_user() {
global $wpdb;
$from_name = get_bloginfo('name');
$from_email = get_bloginfo('admin_email');
// Handle request then generate response using WP_Ajax_Response
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$password = $_POST['password'];
//Add a zero at begining of phone number
if(email_exists($email)){
$save_value = 'email_exists';
}
else if(username_exists($name)){
$save_value = 'username_exists';
}
else {
// $password = wp_generate_password( 10, true, true );
$user_id = wp_create_user($name, $password, $email);
$user_name= sanitize_title_with_dashes($name);
add_user_meta($user_id, 'name', $name);
add_user_meta($user_id, 'email', $email);
add_user_meta($user_id, 'phone', $phone);
add_post_meta($user_id, 'password', $password);
if($user_id){
/////////////// first mail to user - start //////////////////////////////////
$fullname = ucwords(strtolower($user_name));
$subject = "Welcome to ".$from_name;
$message = '<p>Dear '. ucwords(strtolower($email)).',</p><p></p><p>You have successfully created an account to our Website.<br>Your User Name: '.$email.'<br> Your password is : '.$password.'<br>';
//Headers
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
if(!empty($from_email) && filter_var($from_email,FILTER_VALIDATE_EMAIL))//Validating From
$headers .= "From: ".$from_name." <".$from_email."> \r\n";
$reply_email = $from_email;
if($reply_email){
$headers .= "Reply-To: {$reply_email}\r\n";
$headers .= "Return-Path: {$from_name}\r\n";
}
wp_mail($email, $subject, $message , $headers);
/////////////// first mail to user - end //////////////////////////////////
/////////////// Mail to admin - start //////////////////////////////////
$subject = $from_name."- New customer registration request";
$message = '<p>Dear Admin,</p><p>'.$fullname.' is registered in our website!</p><br>User Details are:<br> Name: '.$name.'<br>Phone no:'.$phone.'<br>Email: '.$email.'<br>'
. '<p>Best Wishes,<br>Team '.$from_name;
wp_mail($from_email, $subject, $message , $headers);
/////////////// Mail to admin - end //////////////////////////////////
}
$save_value = "Registration Successful";
}
echo $save_value;
//echo "success==============".$user_id;
die;
}
/***
LOGIN HERE
*/
function custom_login() {
echo header("Location: " . get_bloginfo( 'url' ) . "/register");
}
add_action('login_head', 'custom_login');
function login_link_url( $url ) {
$url = get_bloginfo( 'url' ) . "/register";
return $url;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment