Advertisement
Sumonchandrashil

wer

Jul 6th, 2016
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.57 KB | None | 0 0
  1. <?php
  2.  
  3.    
  4. /*
  5.   Plugin Name: Custom Registration
  6.   Plugin URI: http://code.tutsplus.com
  7.   Description: Updates user rating based on number of posts.
  8.   Version: 1.0
  9.   Author: Agbonghama Collins
  10.   Author URI: http://tech4sky.com
  11.  */
  12.  
  13. function registration_form($fullname, $address, $email, $city, $username, $password, $re_password, $agree) {
  14.  
  15.     echo '
  16. <div class="registration-bg">
  17.     <div class="container">
  18.    <form class="form-signin wow fadeInUp" action="' . $_SERVER['REQUEST_URI'] . '" method="post">
  19.    
  20.     <h2 class="form-signin-heading">Register now</h2>
  21.    
  22.     <div class="login-wrap">
  23.         <p>Enter personal details</p>
  24.         <input type="text" name="fullname" class="form-control" placeholder="Full Name" autofocus="" value="'.(isset($_POST['fullname']) ? $fullname: null ).'">
  25.         <input type="text" name="address" class="form-control" placeholder="Address" autofocus="" value="'.(isset($_POST['address']) ? $address: null ).'">
  26.         <input type="text" name="email" class="form-control" placeholder="Email" autofocus="" value="'.(isset($_POST['email']) ? $email : null ).'">
  27.         <input type="text" name="city" class="form-control" placeholder="City / Town" autofocus="" value="'.(isset($_POST['city']) ? $city : null ).'">
  28.  
  29.         <p> Enter account details below</p>
  30.         <input name="username" type="text" class="form-control" placeholder="User Name" autofocus="" value="'.( isset($_POST['username']) ? $username : null ) .'">
  31.         <input name="password" type="password" class="form-control" placeholder="Password" value="'.( isset($_POST['password']) ? $password : null ).'">
  32.         <input name="re_password" type="password" class="form-control" placeholder="Re-type Password" value="'. ( isset($_POST['re_password']) ? $re_password : null ).'">
  33.        
  34.         <label class="checkbox">
  35.             <input name="agree" type="checkbox" value="'. ( isset($_POST['agree']) ? $agree : false ) .'"> I agree to the Terms of Service and Privacy Policy
  36.         </label>
  37.        
  38.         <button name="submit" value="Register" class="btn btn-lg btn-login btn-block" type="submit">Submit</button>
  39.        
  40.         <div class="registration">
  41.             Already Registered ?
  42.             <a href="' . get_site_url() . '/wp-login.php"> Login </a>
  43.         </div>     
  44.        
  45.     </div>
  46.    </form>
  47. </div></div>   
  48.    ';
  49. }
  50.  
  51. function registration_validation($fullname, $address, $email, $city, $username, $password, $re_password)  {
  52.     global $reg_errors;
  53.     $reg_errors = new WP_Error;
  54.         if ( empty( $fullname ) || empty( $address ) || empty( $email )  || empty( $city ) || empty( $username ) || empty( $password ) || empty( $re_password ) ) {
  55.         $reg_errors->add('field', 'সবগুলো ফিল্ড পূরণ করুন।');
  56.     }
  57.  
  58.    
  59. if ( 4 > strlen( $fullname ) ) {
  60.     $reg_errors->add( 'fullname_length', 'Full Name is too short. At least 4 characters is required' );
  61. }
  62.    
  63. if ( 4 > strlen( $address ) ) {
  64.     $reg_errors->add( 'address_length', 'Full Name is too short. At least 4 characters is required' );
  65. }  
  66.  
  67. if ( 2 > strlen( $city ) ) {
  68.     $reg_errors->add( 'address_length', 'Full Name is too short. At least 4 characters is required' );
  69. }
  70.  
  71.  
  72.  
  73. if ( 4 > strlen( $username ) ) {
  74.     $reg_errors->add( 'username_length', 'Username too short. At least 4 characters is required' );
  75. }
  76.  
  77.  
  78. if ( username_exists( $username ) ){
  79.     $reg_errors->add('user_name', 'Sorry, that username already exists!');
  80. }
  81.  
  82. if ( ! validate_username( $username ) ) {
  83.     $reg_errors->add( 'username_invalid', 'Sorry, the username you entered is not valid' );
  84. }
  85.  
  86. if ( 5 > strlen( $password ) ) {
  87.         $reg_errors->add( 'password', 'Password length must be greater than 5' );
  88.     }
  89.    
  90. if ( !is_email( $email ) ) {
  91.     $reg_errors->add( 'email_invalid', 'Email is not valid' );
  92. }
  93. if ( email_exists( $email ) ) {
  94.     $reg_errors->add( 'email', 'Email Already in use' );
  95. }
  96.  
  97. if ( $re_password <> $password) {
  98.     $reg_errors->add( 're_password', 'Password Not Match' );
  99. }
  100.  
  101.  
  102. if ( is_wp_error( $reg_errors ) ) {
  103.     foreach ( $reg_errors->get_error_messages() as $error ) {
  104.         echo '<div>';
  105.         echo '<strong> ERROR </strong> : ';
  106.         echo $error . '<br/>';
  107.         echo '</div>';
  108.     }
  109. }
  110.  
  111. }
  112.  
  113.  
  114. function complete_registration() {
  115.     global $reg_errors, $fullname, $address, $email, $city, $username, $password, $re_password, $agree;
  116.     if ( 1 > count( $reg_errors->get_error_messages() ) ) {
  117.         $userdata = array(
  118.         'fullname'      =>   $fullname,
  119.         'address'       =>   $address,
  120.         'user_email'    =>   $email,       
  121.         'city'          =>   $city,
  122.         'user_login'    =>   $username,
  123.         'password'     =>   $password,
  124.         're_password'     =>   $re_password,
  125.         'agree'     =>   $agree,
  126.         );
  127.         $user = wp_insert_user( $userdata );
  128.         echo 'Registration complete. Goto <a href="' . get_site_url() . '/wp-login.php">login page</a>.';  
  129.     }
  130. }
  131.  
  132.  
  133. function custom_registration_function() {
  134.     if ( isset($_POST['submit'] ) ) {
  135.         registration_validation(
  136.         $_POST['fullname'],
  137.         $_POST['address'],
  138.         $_POST['email'],       
  139.         $_POST['city'],
  140.         $_POST['username'],
  141.         $_POST['password'],
  142.         $_POST['re_password'],
  143.         $_POST['agree']
  144.         );
  145.          
  146.         // sanitize user form input
  147.         global $fullname, $address, $email, $city, $username, $password, $re_password, $agree;
  148.         $fullname   =   sanitize_text_field( $_POST['fullname'] );
  149.         $address   =   sanitize_text_field( $_POST['address'] );
  150.         $email      =   sanitize_email( $_POST['email'] );
  151.         $city   =   sanitize_text_field( $_POST['city'] );
  152.         $username   =   sanitize_user( $_POST['username'] );
  153.         $password   =   esc_attr( $_POST['password'] );
  154.         $re_password   =   esc_attr( $_POST['re_password'] );
  155.         $agree   =   filter_var($agree, FILTER_SANITIZE_NUMBER_INT);
  156.  
  157.  
  158.        
  159.         // call @function complete_registration to create the user
  160.         // only when no WP_error is found
  161.         complete_registration(
  162.         $fullname,
  163.         $address,
  164.         $email,    
  165.         $city,
  166.         $username,
  167.         $password,
  168.         $re_password,
  169.         $agree
  170.         );
  171.     }
  172.  
  173.     registration_form(
  174.         $fullname,
  175.         $address,
  176.         $email,
  177.         $city,
  178.         $username,
  179.         $password,
  180.         $re_password,
  181.         $agree
  182.     );
  183. }
  184.  
  185.  
  186.  
  187. // Register a new shortcode: [cr_custom_registration]
  188. add_shortcode( 'cr_custom_registration', 'custom_registration_shortcode' );
  189.  
  190. // The callback function that will replace [book]
  191. function custom_registration_shortcode() {
  192.     ob_start();
  193.     custom_registration_function();
  194.     return ob_get_clean();
  195. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement