function rcl_register_user_data($user_id)
{
    update_user_meta($user_id, 'show_admin_bar_front', 'false');
    $cf = new Rcl_Custom_Fields();
    $cf->register_user_metas($user_id);
}
function rcl_register_user_order()
{
    global $rmag_options, $wpdb, $order, $rcl_options;
    $reg_user = $rmag_options['noreg_order'] ? false : true;
    $fio_new_user = sanitize_text_field($_POST['fio_new_user']);
    $email_new_user = sanitize_email($_POST['email_new_user']);
    include_once 'rcl_order.php';
    $ord = new Rcl_Order();
    $get_fields = get_option('custom_profile_field');
    $get_order_fields = get_option('custom_orders_field');
    $req_prof = $ord->chek_requared_fields($get_fields, 'profile');
    $req_order = $ord->chek_requared_fields($get_order_fields);
    if ($email_new_user && $req_prof && $req_order) {
        $res_email = email_exists($email_new_user);
        $res_login = username_exists($email_new_user);
        $correctemail = is_email($email_new_user);
        $valid = validate_username($email_new_user);
        if (!$reg_user && (!$correctemail || !$valid)) {
            if (!$valid || !$correctemail) {
                $log['int'] = 1;
                $log['recall'] = '<p style="text-align:center;color:red;">Вы ввели некорректный email!</p>';
                echo json_encode($res);
                exit;
            }
        }
        //var_dump($reg_user);exit;
        if ($reg_user && ($res_login || $res_email || !$correctemail || !$valid)) {
            if (!$valid || !$correctemail) {
                $log['int'] = 1;
                $log['recall'] .= '<p style="text-align:center;color:red;">Вы ввели некорректный email!</p>';
            }
            if ($res_login || $res_email) {
                $log['int'] = 1;
                $log['recall'] .= '<p style="text-align:center;color:red;">Этот email уже используется!<br>' . 'Если это ваш email, то авторизуйтесь и продолжите оформление заказа.</p>';
            }
        } else {
            $user_id = false;
            if (!$reg_user) {
                $user = get_user_by('email', $email_new_user);
                if ($user) {
                    $user_id = $user->ID;
                }
            }
            if (!$user_id) {
                $random_password = wp_generate_password($length = 12, $include_standard_special_chars = false);
                $userdata = array('user_pass' => $random_password, 'user_login' => $email_new_user, 'user_email' => $email_new_user, 'display_name' => $fio_new_user);
                $user_id = rcl_insert_user($userdata);
            }
            if ($user_id) {
                if ($get_fields && $user_id) {
                    $cf = new Rcl_Custom_Fields();
                    $cf->register_user_metas($user_id);
                }
                //Сразу авторизуем пользователя
                if ($reg_user && !$rcl_options['confirm_register_recall']) {
                    $creds = array();
                    $creds['user_login'] = $email_new_user;
                    $creds['user_password'] = $random_password;
                    $creds['remember'] = true;
                    $user = wp_signon($creds, false);
                    $redirect_url = rcl_format_url(get_author_posts_url($user_id), 'orders');
                } else {
                    $redirect_url = false;
                }
                $order_id = $ord->get_order_id();
                $results = $ord->insert_order($order_id, $user_id);
                if (!$results) {
                    $log['int'] = 1;
                    $log['recall'] = '<p style="text-align:center;color:red;">Возникла ошибка, заказ не был создан!</p>';
                    echo json_encode($log);
                    exit;
                }
                $order_custom_field = $ord->insert_detail_order($get_order_fields);
                $order = rcl_get_order($order_id);
                $table_order = rcl_get_include_template('order.php', __FILE__);
                $ord->send_mail($order_custom_field, $table_order, $user_id, $creds);
                $notice = $rcl_options['confirm_register_recall'] == 1 ? '<p class=res_confirm style="color:orange;">Для отслеживания статуса заказа подтвердите указанный email!<br>' . 'Перейдите по ссылке в высланном письме.</p>' : '';
                if (!$order->order_price) {
                    //Если заказ бесплатный
                    $notice .= "<p class='res_confirm'>Ваш заказ был создан!<br />" . "Заказ содержал только бесплатные товары<br>" . "Заказу присвоен статус - \"Оплачено\"<br>" . "Заказ поступил в обработку. В своем личном кабинете вы можете узнать статус вашего заказа.</p>";
                    $log['recall'] = $notice;
                    $log['redirect'] = $redirect_url;
                    $log['int'] = 100;
                    echo json_encode($log);
                    exit;
                }
                if (function_exists('rcl_payform')) {
                    $type_order_payment = $rmag_options['type_order_payment'];
                    if ($type_order_payment == 1 || $type_order_payment == 2) {
                        $notice .= "<p class='res_confirm'>Ваш заказ был создан!<br />Заказу присвоен статус - \"Неоплачено\"<br />Вы можете оплатить его сейчас или из своего ЛК. Там же вы можете узнать статус вашего заказа.</p>";
                        if ($type_order_payment == 2) {
                            $notice .= "<p class='res_confirm'>Вы можете пополнить свой личный счет на сайте из своего личного кабинета и в будущем оплачивать свои заказы через него</p>";
                        }
                        if (!$rcl_options['confirm_register_recall']) {
                            $notice .= "<p align='center'><a href='" . $redirect_url . "'>Перейти в свой личный кабинет</a></p>";
                            $notice .= rcl_payform(array('id_pay' => $order_id, 'summ' => $order->order_price, 'user_id' => $user_id, 'type' => 2));
                        }
                        $log['recall'] = $notice;
                        $log['redirect'] = 0;
                        $log['int'] = 100;
                    } else {
                        $log['int'] = 100;
                        $log['redirect'] = $redirect_url;
                        $notice .= "<p class=res_confirm>Ваш заказ был создан!<br />Проверьте свою почту.</p>";
                        $log['recall'] = $notice;
                    }
                } else {
                    $log['int'] = 100;
                    $log['redirect'] = $redirect_url;
                    $notice .= '<p class=res_confirm>Ваш заказ был создан!<br />Проверьте свою почту.</p>';
                    $log['recall'] = $notice;
                }
            }
        }
    } else {
        $log['int'] = 1;
        $log['recall'] = '<p style="text-align:center;color:red;">Пожалуйста, заполните все обязательные поля!</p>';
    }
    echo json_encode($log);
    exit;
}