Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: Custom Registration
- Plugin URI: http://code.tutsplus.com
- Description: Updates user rating based on number of posts.
- Version: 1.0
- Author: Agbonghama Collins
- Author URI: http://tech4sky.com
- */
- function registration_form($fullname, $address, $email, $city, $username, $password, $re_password, $agree) {
- echo '
- <div class="registration-bg">
- <div class="container">
- <form class="form-signin wow fadeInUp" action="' . $_SERVER['REQUEST_URI'] . '" method="post">
- <h2 class="form-signin-heading">Register now</h2>
- <div class="login-wrap">
- <p>Enter personal details</p>
- <input type="text" name="fullname" class="form-control" placeholder="Full Name" autofocus="" value="'.(isset($_POST['fullname']) ? $fullname: null ).'">
- <input type="text" name="address" class="form-control" placeholder="Address" autofocus="" value="'.(isset($_POST['address']) ? $address: null ).'">
- <input type="text" name="email" class="form-control" placeholder="Email" autofocus="" value="'.(isset($_POST['email']) ? $email : null ).'">
- <input type="text" name="city" class="form-control" placeholder="City / Town" autofocus="" value="'.(isset($_POST['city']) ? $city : null ).'">
- <p> Enter account details below</p>
- <input name="username" type="text" class="form-control" placeholder="User Name" autofocus="" value="'.( isset($_POST['username']) ? $username : null ) .'">
- <input name="password" type="password" class="form-control" placeholder="Password" value="'.( isset($_POST['password']) ? $password : null ).'">
- <input name="re_password" type="password" class="form-control" placeholder="Re-type Password" value="'. ( isset($_POST['re_password']) ? $re_password : null ).'">
- <label class="checkbox">
- <input name="agree" type="checkbox" value="'. ( isset($_POST['agree']) ? $agree : false ) .'"> I agree to the Terms of Service and Privacy Policy
- </label>
- <button name="submit" value="Register" class="btn btn-lg btn-login btn-block" type="submit">Submit</button>
- <div class="registration">
- Already Registered ?
- <a href="' . get_site_url() . '/wp-login.php"> Login </a>
- </div>
- </div>
- </form>
- </div></div>
- ';
- }
- function registration_validation($fullname, $address, $email, $city, $username, $password, $re_password) {
- global $reg_errors;
- $reg_errors = new WP_Error;
- if ( empty( $fullname ) || empty( $address ) || empty( $email ) || empty( $city ) || empty( $username ) || empty( $password ) || empty( $re_password ) ) {
- $reg_errors->add('field', 'সবগুলো ফিল্ড পূরণ করুন।');
- }
- if ( 4 > strlen( $fullname ) ) {
- $reg_errors->add( 'fullname_length', 'Full Name is too short. At least 4 characters is required' );
- }
- if ( 4 > strlen( $address ) ) {
- $reg_errors->add( 'address_length', 'Full Name is too short. At least 4 characters is required' );
- }
- if ( 2 > strlen( $city ) ) {
- $reg_errors->add( 'address_length', 'Full Name is too short. At least 4 characters is required' );
- }
- if ( 4 > strlen( $username ) ) {
- $reg_errors->add( 'username_length', 'Username too short. At least 4 characters is required' );
- }
- if ( username_exists( $username ) ){
- $reg_errors->add('user_name', 'Sorry, that username already exists!');
- }
- if ( ! validate_username( $username ) ) {
- $reg_errors->add( 'username_invalid', 'Sorry, the username you entered is not valid' );
- }
- if ( 5 > strlen( $password ) ) {
- $reg_errors->add( 'password', 'Password length must be greater than 5' );
- }
- if ( !is_email( $email ) ) {
- $reg_errors->add( 'email_invalid', 'Email is not valid' );
- }
- if ( email_exists( $email ) ) {
- $reg_errors->add( 'email', 'Email Already in use' );
- }
- if ( $re_password <> $password) {
- $reg_errors->add( 're_password', 'Password Not Match' );
- }
- if ( is_wp_error( $reg_errors ) ) {
- foreach ( $reg_errors->get_error_messages() as $error ) {
- echo '<div>';
- echo '<strong> ERROR </strong> : ';
- echo $error . '<br/>';
- echo '</div>';
- }
- }
- }
- function complete_registration() {
- global $reg_errors, $fullname, $address, $email, $city, $username, $password, $re_password, $agree;
- if ( 1 > count( $reg_errors->get_error_messages() ) ) {
- $userdata = array(
- 'fullname' => $fullname,
- 'address' => $address,
- 'user_email' => $email,
- 'city' => $city,
- 'user_login' => $username,
- 'password' => $password,
- 're_password' => $re_password,
- 'agree' => $agree,
- );
- $user = wp_insert_user( $userdata );
- echo 'Registration complete. Goto <a href="' . get_site_url() . '/wp-login.php">login page</a>.';
- }
- }
- function custom_registration_function() {
- if ( isset($_POST['submit'] ) ) {
- registration_validation(
- $_POST['fullname'],
- $_POST['address'],
- $_POST['email'],
- $_POST['city'],
- $_POST['username'],
- $_POST['password'],
- $_POST['re_password'],
- $_POST['agree']
- );
- // sanitize user form input
- global $fullname, $address, $email, $city, $username, $password, $re_password, $agree;
- $fullname = sanitize_text_field( $_POST['fullname'] );
- $address = sanitize_text_field( $_POST['address'] );
- $email = sanitize_email( $_POST['email'] );
- $city = sanitize_text_field( $_POST['city'] );
- $username = sanitize_user( $_POST['username'] );
- $password = esc_attr( $_POST['password'] );
- $re_password = esc_attr( $_POST['re_password'] );
- $agree = filter_var($agree, FILTER_SANITIZE_NUMBER_INT);
- // call @function complete_registration to create the user
- // only when no WP_error is found
- complete_registration(
- $fullname,
- $address,
- $email,
- $city,
- $username,
- $password,
- $re_password,
- $agree
- );
- }
- registration_form(
- $fullname,
- $address,
- $email,
- $city,
- $username,
- $password,
- $re_password,
- $agree
- );
- }
- // Register a new shortcode: [cr_custom_registration]
- add_shortcode( 'cr_custom_registration', 'custom_registration_shortcode' );
- // The callback function that will replace [book]
- function custom_registration_shortcode() {
- ob_start();
- custom_registration_function();
- return ob_get_clean();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement