function rcl_register_author_post($postdata)
{
    global $user_ID, $rcl_options, $wpdb;
    $user_can = $rcl_options['user_public_access_recall'];
    if ($user_can || $user_ID) {
        return $postdata;
    }
    if (!$postdata['post_author']) {
        $email_new_user = sanitize_email($_POST['email-user']);
        if ($email_new_user) {
            $user_id = false;
            $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' => $_POST['name-user']);
            $user_id = rcl_insert_user($userdata);
            if ($user_id) {
                //Сразу авторизуем пользователя
                if (!$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);
                    $user_ID = $user_id;
                }
                $postdata['post_author'] = $user_id;
                $postdata['post_status'] = 'pending';
            }
        }
    }
    return $postdata;
}
Esempio n. 2
0
function rcl_get_register_user($errors)
{
    global $wpdb, $rcl_options, $wp_errors;
    $wp_errors = new WP_Error();
    if (count($errors->errors)) {
        $wp_errors = $errors;
        return $wp_errors;
    }
    $pass = sanitize_text_field($_POST['user_pass']);
    $email = $_POST['user_email'];
    $login = sanitize_user($_POST['user_login']);
    //print_r($_POST);exit;
    $ref = $_POST['redirect_to'] ? apply_filters('url_after_register_rcl', esc_url($_POST['redirect_to'])) : wp_registration_url();
    $get_fields = get_option('custom_profile_field');
    $requared = true;
    if ($get_fields) {
        foreach ((array) $get_fields as $custom_field) {
            $custom_field = apply_filters('chek_custom_field_regform', $custom_field);
            if (!$custom_field) {
                continue;
            }
            $slug = $custom_field['slug'];
            if ($custom_field['requared'] == 1 && $custom_field['register'] == 1) {
                if ($custom_field['type'] == 'checkbox') {
                    $chek = explode('#', $custom_field['field_select']);
                    $count_field = count($chek);
                    for ($a = 0; $a < $count_field; $a++) {
                        if (!isset($_POST[$slug][$a])) {
                            $requared = false;
                        } else {
                            $requared = true;
                            break;
                        }
                    }
                } else {
                    if ($custom_field['type'] == 'file') {
                        if (!isset($_FILES[$slug])) {
                            $requared = false;
                        }
                    } else {
                        if (!$_POST[$slug]) {
                            $requared = false;
                        }
                    }
                }
            }
        }
    }
    if (!$pass || !$email || !$login || !$requared) {
        $wp_errors->add('rcl_register_empty', __('Fill in the required fields!', 'wp-recall'));
        return $wp_errors;
    }
    $wp_errors = apply_filters('rcl_registration_errors', $wp_errors, $login, $email);
    if ($wp_errors->errors) {
        return $wp_errors;
    }
    do_action('pre_register_user_rcl', $ref);
    //регистрируем юзера с указанными данными
    $userdata = array('user_pass' => $pass, 'user_login' => $login, 'user_email' => $email, 'display_name' => $fio);
    $user_id = rcl_insert_user($userdata);
    if ($user_id) {
        if ($rcl_options['login_form_recall'] == 2 || false !== strpos($ref, 'wp-login.php')) {
            //если форма ВП, то возвращаем на login с нужными GET-параметрами
            if ($rcl_options['confirm_register_recall'] == 1) {
                wp_safe_redirect('wp-login.php?checkemail=confirm');
            } else {
                wp_safe_redirect('wp-login.php?checkemail=registered');
            }
        } else {
            //иначе возвращаем на ту же страницу
            if ($rcl_options['confirm_register_recall'] == 1) {
                wp_redirect(rcl_format_url($ref) . 'action-rcl=register&success=confirm-email');
            } else {
                wp_redirect(rcl_format_url($ref) . 'action-rcl=register&success=true');
            }
        }
        exit;
    }
}
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;
}