Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if( !function_exists('reviews_register') ){
- function reviews_register(){
- $response = array();
- $registration_terms = reviews_get_option( 'registration_terms' );
- $fileSupportArray = array("jpeg", "png", "jpg", "gif", "JPG");
- $exploded = explode(".", $_FILES['image']['name']);
- $ext = end($exploded);
- if( wp_verify_nonce($_POST['register_field'], 'register') ){
- $username = isset( $_POST['username'] ) ? $_POST['username'] : '';
- $email = isset( $_POST['email'] ) ? $_POST['email'] : '';
- $password = isset( $_POST['password'] ) ? $_POST['password'] : '';
- $repeat_password = isset( $_POST['repeat_password'] ) ? $_POST['repeat_password'] : '';
- $image = isset( $_FILES['image']['name'] ) ? $_FILES['image']['name'] : '';
- $terms = isset( $_POST['terms'] ) ? true : false;
- if( empty( $registration_terms ) ){
- $terms = true;
- }
- if( $terms ){
- if( empty( $_POST['captcha'] ) ){
- if( !empty( $username ) ){
- if(!empty( $image )){
- //if(!empty( $image ) && !in_array($ext, $fileSupportArray)){
- if( !empty( $email ) && filter_var($email, FILTER_VALIDATE_EMAIL) ){
- if( !empty( $password ) && !empty( $repeat_password ) && $password == $repeat_password ){
- if( !username_exists( $username ) ){
- if( !email_exists( $email ) ){
- $user_id = wp_insert_user(array(
- 'user_login' => $username,
- 'user_pass' => $password,
- 'user_email' => $email
- ));
- if( !is_wp_error($user_id) ) {
- wp_update_user(array(
- 'ID' => $user_id,
- ));
- $confirmation_hash = reviews_random_string(10);
- update_user_meta( $user_id, 'user_active_status', 'inactive' );
- update_user_meta( $user_id, 'confirmation_hash', $confirmation_hash );
- $confirmation_message = reviews_get_option( 'registration_message' );
- $confirmation_link = reviews_get_permalink_by_tpl( 'page-tpl_register_login' );
- $confirmation_link = esc_url( add_query_arg( array( 'username' => $username, 'confirmation_hash' => $confirmation_hash ), $confirmation_link ) );
- $confirmation_message = str_replace( '%LINK%', $confirmation_link, $confirmation_message );
- $registration_subject = reviews_get_option( 'registration_subject' );
- $email_sender = reviews_get_option( 'sender_email' );
- $name_sender = reviews_get_option( 'sender_name' );
- $headers = array();
- $headers[] = "MIME-Version: 1.0";
- $headers[] = "Content-Type: text/html; charset=UTF-8";
- $headers[] = "From: ".esc_attr( $name_sender )." <".esc_attr( $email_sender ).">";
- $info = @wp_mail( $email, $registration_subject, $confirmation_message, $headers );
- if( $info ){
- $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>';
- }
- else{
- $response['message'] = '<div class="alert alert-danger">'.esc_html__( 'There was an error trying to send confirmation link to you', 'reviews' ).'</div>';
- }
- }
- else{
- $response['message'] = '<div class="alert alert-danger">'.esc_html__( 'There was an error trying to register you', 'reviews' ).'</div>';
- }
- }
- else{
- $response['message'] = '<div class="alert alert-danger">'.esc_html__( 'Email is already registered', 'reviews' ).'</div>';
- }
- }
- else{
- $response['message'] = '<div class="alert alert-danger">'.esc_html__( 'Username is already taken', 'reviews' ).'</div>';
- }
- }
- else{
- $response['message'] = '<div class="alert alert-danger">'.esc_html__( 'Passwords do not match', 'reviews' ).'</div>';
- }
- }
- else{
- $response['message'] = '<div class="alert alert-danger">'.esc_html__( 'Email is invalid', 'reviews' ).'</div>';
- }
- }
- else{
- $response['message'] = '<div class="alert alert-danger">'.esc_html__( 'Image Empty', 'reviews' ).'</div>';
- }
- }
- else{
- $response['message'] = '<div class="alert alert-danger">'.esc_html__( 'File Format not Supported', 'reviews' ).'</div>';
- }
- }
- else{
- $response['message'] = '<div class="alert alert-danger">'.esc_html__( 'Username is empty', 'reviews' ).'</div>';
- }
- }
- else{
- $response['message'] = '<div class="alert alert-danger">'.esc_html__( 'Captcha is wrong.', 'reviews' ).'</div>';
- }
- }
- else{
- $response['message'] = '<div class="alert alert-danger">'.esc_html__( 'You need to accept terms & conditions', 'reviews' ).'</div>';
- }
- }
- else{
- $response['message'] = '<div class="alert alert-danger">'.esc_html__( 'You do not have permission for this action', 'reviews' ).'</div>';
- }
- echo json_encode( $response );
- die();
- }
- add_action('wp_ajax_register', 'reviews_register');
- add_action('wp_ajax_nopriv_register', 'reviews_register');
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement