Advertisement
ayeniblessing

register.php

Mar 29th, 2016
415
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.80 KB | None | 0 0
  1. <?php
  2.  
  3. if( !function_exists('reviews_register') ){
  4. function reviews_register(){
  5.     $response = array();
  6.     $registration_terms = reviews_get_option( 'registration_terms' );
  7.     $fileSupportArray = array("jpeg", "png", "jpg", "gif", "JPG");
  8.     $exploded = explode(".", $_FILES['image']['name']);
  9.     $ext = end($exploded);
  10.  
  11.     if( wp_verify_nonce($_POST['register_field'], 'register') ){
  12.         $username = isset( $_POST['username'] ) ? $_POST['username'] : '';
  13.         $email = isset( $_POST['email'] ) ? $_POST['email'] : '';
  14.         $password = isset( $_POST['password'] ) ? $_POST['password'] : '';
  15.         $repeat_password = isset( $_POST['repeat_password'] ) ? $_POST['repeat_password'] : '';
  16.         $image = isset( $_FILES['image']['name'] ) ? $_FILES['image']['name'] : '';
  17.         $terms = isset( $_POST['terms'] ) ? true : false;
  18.         if( empty( $registration_terms ) ){
  19.             $terms = true;
  20.         }
  21.         if( $terms ){
  22.             if( empty( $_POST['captcha'] ) ){
  23.                 if( !empty( $username ) ){
  24.                     if(!empty( $image )){
  25.                     //if(!empty( $image ) && !in_array($ext, $fileSupportArray)){
  26.                     if( !empty( $email ) && filter_var($email, FILTER_VALIDATE_EMAIL) ){
  27.                         if( !empty( $password ) && !empty( $repeat_password ) && $password == $repeat_password ){
  28.                             if( !username_exists( $username ) ){
  29.                                 if( !email_exists( $email ) ){
  30.                                     $user_id = wp_insert_user(array(
  31.                                         'user_login'  => $username,
  32.                                         'user_pass'   => $password,
  33.                                         'user_email'  => $email
  34.                                     ));
  35.                                     if( !is_wp_error($user_id) ) {
  36.                                         wp_update_user(array(
  37.                                             'ID' => $user_id,
  38.                                         ));                            
  39.                                         $confirmation_hash = reviews_random_string(10);
  40.                                         update_user_meta( $user_id, 'user_active_status', 'inactive' );
  41.                                         update_user_meta( $user_id, 'confirmation_hash', $confirmation_hash );
  42.  
  43.                                         $confirmation_message = reviews_get_option( 'registration_message' );
  44.                                         $confirmation_link = reviews_get_permalink_by_tpl( 'page-tpl_register_login' );
  45.                                         $confirmation_link = esc_url( add_query_arg( array( 'username' => $username, 'confirmation_hash' => $confirmation_hash ), $confirmation_link ) );
  46.                                        
  47.                                         $confirmation_message = str_replace( '%LINK%', $confirmation_link, $confirmation_message );
  48.  
  49.                                         $registration_subject = reviews_get_option( 'registration_subject' );
  50.  
  51.                                         $email_sender = reviews_get_option( 'sender_email' );
  52.                                         $name_sender = reviews_get_option( 'sender_name' );
  53.                                         $headers   = array();
  54.                                         $headers[] = "MIME-Version: 1.0";
  55.                                         $headers[] = "Content-Type: text/html; charset=UTF-8";
  56.                                         $headers[] = "From: ".esc_attr( $name_sender )." <".esc_attr( $email_sender ).">";
  57.  
  58.                                         $info = @wp_mail( $email, $registration_subject, $confirmation_message, $headers );
  59.                                         if( $info ){
  60.                                             $response['message'] = '<div class="alert alert-success">'.esc_html__( 'You have registered. Email with the confirmation link is sent on the email address you have provided.', 'reviews' ).'</div>';
  61.                                         }
  62.                                         else{
  63.                                             $response['message'] = '<div class="alert alert-danger">'.esc_html__( 'There was an error trying to send confirmation link to you', 'reviews' ).'</div>';
  64.                                         }                            
  65.  
  66.                                     }
  67.                                     else{
  68.                                         $response['message'] = '<div class="alert alert-danger">'.esc_html__( 'There was an error trying to register you', 'reviews' ).'</div>';
  69.                                     }
  70.                                 }
  71.                                 else{
  72.                                     $response['message'] = '<div class="alert alert-danger">'.esc_html__( 'Email is already registered', 'reviews' ).'</div>';                 
  73.                                 }
  74.                             }
  75.                             else{
  76.                                 $response['message'] = '<div class="alert alert-danger">'.esc_html__( 'Username is already taken', 'reviews' ).'</div>';           
  77.                             }
  78.                         }
  79.                         else{
  80.                             $response['message'] = '<div class="alert alert-danger">'.esc_html__( 'Passwords do not match', 'reviews' ).'</div>';      
  81.                         }
  82.                     }
  83.                     else{
  84.                         $response['message'] = '<div class="alert alert-danger">'.esc_html__( 'Email is invalid', 'reviews' ).'</div>';
  85.                     }
  86.                    
  87.                     }
  88.                     else{
  89.                         $response['message'] = '<div class="alert alert-danger">'.esc_html__( 'Image Empty', 'reviews' ).'</div>'; 
  90.                     }
  91.                     }
  92.                     else{
  93.                         $response['message'] = '<div class="alert alert-danger">'.esc_html__( 'File Format not Supported', 'reviews' ).'</div>';
  94.                     }
  95.                 }
  96.                 else{
  97.                     $response['message'] = '<div class="alert alert-danger">'.esc_html__( 'Username is empty', 'reviews' ).'</div>';
  98.                 }
  99.             }
  100.             else{
  101.                 $response['message'] = '<div class="alert alert-danger">'.esc_html__( 'Captcha is wrong.', 'reviews' ).'</div>';
  102.             }
  103.         }
  104.         else{
  105.             $response['message'] = '<div class="alert alert-danger">'.esc_html__( 'You need to accept terms & conditions', 'reviews' ).'</div>';
  106.         }
  107.     }
  108.     else{
  109.         $response['message'] = '<div class="alert alert-danger">'.esc_html__( 'You do not have permission for this action', 'reviews' ).'</div>';
  110.     }
  111.     echo json_encode( $response );
  112.     die();
  113. }
  114. add_action('wp_ajax_register', 'reviews_register');
  115. add_action('wp_ajax_nopriv_register', 'reviews_register');
  116. }
  117.  
  118.  
  119. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement