HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux wordpress-ubuntu-s-2vcpu-4gb-fra1-01 5.4.0-169-generic #187-Ubuntu SMP Thu Nov 23 14:52:28 UTC 2023 x86_64
User: root (0)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/dinamo-shop/wp-content/plugins/dinamo-plugin/account/registration.php
<?php
/*
 * File containing functions for user registration
 */


add_action( 'wp_ajax_user_registration', 'user_registration' );
function user_registration() {

  // save posted form data
  $user_first_name  = $_POST['user_name'];
  $user_last_name   = $_POST['user_surname'];
  $user_email       = $_POST['user_email'];
  $user_email_check = $_POST['user_email_check'];
  $user_pass        = $_POST['user_pass'];
  $user_pass_check  = $_POST['user_pass_check'];


  // check if emails match
  if( strcmp( $user_email, $user_email_check ) !== 0 ) {
    echo json_encode(array(
      'success' => false,
      'message' => 'Unesene e-mail adrese se ne podudaraju.'
    ));

    die();
    return;
  }

  // check if passwords match
  if( strcmp( $user_pass, $user_pass_check ) !== 0 ) {
    echo json_encode(array(
      'success' => false,
      'message' => 'Unesene lozinke se ne podudaraju.'
    ));

    die();
    return;
  }

  // create new user (customer)
  $user_id = wc_create_new_customer( sanitize_email( $user_email ), wc_clean( $user_email ), $user_password );


  if( ! is_wp_error( $user_id) && is_numeric( $user_id ) ) {

    $data = array(
      'billing_email'      => $user_email,
      'billing_first_name' => $user_first_name,
      'billing_last_name'  => $user_last_name,
    );

    foreach( $data as $key => $value ){
      update_user_meta( $user_id, $key, $value );
    }

  } elseif( is_wp_error( $user_id ) ) {

    $error = array(
      'error'   => "Wordpress insert error",
      'details' => $user_id->errors
    );

    if ( isset($user_id->errors['empty_user_login']) ) {

      echo json_encode(array(
        'success' => false,
        'message' => 'Email adresa je obvezno polje. Molimo ispuni email adresu i pokušaj ponovo.'
      ));

    } elseif ( isset($user_id->errors['existing_user_login']) || isset($user_id->errors['existing_user_email']) || isset($user_id->errors['registration-error-email-exists'])) {


      echo json_encode(array(
          'success' => false,
          'message' => 'Korisnik s tom email adresom već postoji. Ako već imaš korisnički račun,molimo te da klikneš na prijavu u glavnom izborniku.'
      ));


    } else {


      echo json_encode(array(
          'success' => false,
          'message' => 'Došlo je do nepoznate pogreške. Molimo pokušaj kasnije.'
      ));

    }

  } else if ( ! is_numeric( $user_id ) ) {

      $error = array(
        'error'    => "Wordpress insert error",
        'details' => $user_id
      );

      echo json_encode(array(
          'success' => false,
          'message' => 'Došlo je do nepoznate pogreške. Molimo pokušaj kasnije.'
      ));


    }


    die();
    return;

}