Esempio n. 1
0
function aione_login_form_shortcode($attr, $content = null)
{
    // Attributes
    extract(shortcode_atts(array('echo' => false, 'redirect' => get_option('admin_login_redirect_page'), 'form_id' => 'loginform', 'label_username' => __('Username'), 'label_password' => __('Password'), 'label_remember' => __('Remember Me'), 'label_log_in' => __('Login'), 'id_username' => 'user_login', 'id_password' => 'user_pass', 'id_remember' => 'rememberme', 'id_submit' => 'wp-submit'), $atts));
    $output = "";
    $login = $_GET['login'];
    $errors = array();
    if (isset($login) && $login == 'failed') {
        $errors[] = 'Invalid username or password';
        $output .= aione_show_errors($errors);
    }
    //print_r($_POST);
    //print_r($_GET);
    $args = array('echo' => $echo, 'redirect' => $redirect, 'form_id' => $form_id, 'label_username' => $label_username, 'label_password' => $label_password, 'label_remember' => $label_remember, 'label_log_in' => $label_log_in, 'id_username' => $id_username, 'id_password' => $id_password, 'id_remember' => $id_remember, 'id_submit' => $id_submit, 'remember' => empty($instance['remember']) ? true : false, 'value_username' => esc_attr($instance['value_username']), 'value_remember' => !empty($instance['value_remember']) ? true : false);
    $output .= wp_login_form($args);
    return $output;
}
Esempio n. 2
0
function aione_register_shortcode($atts)
{
    // Attributes
    extract(shortcode_atts(array(), $atts));
    $output = "";
    // only show the registration form to non-logged-in members
    if (!is_user_logged_in()) {
        global $aione_load_css;
        // set this to true so the CSS is loaded
        $aione_load_css = true;
        // check to make sure user registration is enabled
        $registration_enabled = get_option('users_can_register');
        // only show the registration form if allowed
        if ($registration_enabled) {
            $errors = array();
            // load from post
            if (isset($_POST['action']) && $_POST['action'] == 'add_new' && !empty($_POST['fields'])) {
                $user_login = $_POST["aione_user_login"];
                $user_email = $_POST["aione_user_email"];
                $user_pass = $_POST["aione_user_pass"];
                $pass_confirm = $_POST["aione_user_pass_confirm"];
                // this is required for username checks
                require_once ABSPATH . WPINC . '/registration.php';
                if ($user_email == '') {
                    //empty email
                    $errors[] = 'Please enter email address';
                } else {
                    if (!is_email($user_email)) {
                        //invalid email
                        $errors[] = 'Invalid email';
                    }
                    if (email_exists($user_email)) {
                        //Email address already registered
                        $errors[] = 'Email already registered';
                    }
                }
                if ($user_login == '') {
                    // empty username
                    $errors[] = 'Please enter a username';
                } else {
                    if (!validate_username($user_login)) {
                        // invalid username
                        $errors[] = 'Invalid username';
                    }
                    if (username_exists($user_login)) {
                        // Username already registered
                        $errors[] = 'Username already taken';
                    }
                }
                if ($user_pass == '') {
                    //Empty password
                    $errors[] = 'Please enter a password';
                }
                if ($user_pass != $pass_confirm) {
                    // passwords do not match
                    $errors[] = 'Passwords do not match';
                }
                if (!empty($user_first) && !preg_match('/^[a-zA-Z\\s]+$/', $user_first)) {
                    //Invalid Mobile
                    $errors[] = 'Invalid first name. Numbers not allowed.';
                }
                if (!empty($user_last) && !preg_match('/^[a-zA-Z\\s]+$/', $user_last)) {
                    //Invalid Mobile
                    $errors[] = 'Invalid last name. Numbers not allowed.';
                }
                // only create the user in if there are no errors
                if (empty($errors)) {
                    $user_role = get_option('default_role');
                    $new_user_id = wp_insert_user(array('user_login' => $user_login, 'user_pass' => $user_pass, 'user_email' => $user_email, 'first_name' => $user_first, 'last_name' => $user_last, 'user_registered' => date('Y-m-d H:i:s'), 'role' => $user_role));
                    if (is_int($new_user_id)) {
                        // loop through and save $_POST data
                        foreach ($_POST['fields'] as $k => $v) {
                            // get field
                            $f = apply_filters('acf/load_field', false, $k);
                            // update field
                            do_action('acf/update_value', $v, $post_id, $f);
                        }
                        // foreach
                        $output .= 'You have been successfully registered.';
                        //wp_redirect($redirect_url);
                        /*
                        $output .= '<script type="text/javascript">
                        <!--
                           window.location="'.$redirect_url.'";
                        //-->
                        </script>';
                        */
                    } else {
                        $errors[] = 'Some error occurred. Please contact Administrator.';
                    }
                } else {
                    $output .= aione_show_errors($errors);
                }
            }
            $output .= aione_user_registration_form();
        } else {
            $output .= __('User registration is not enabled');
        }
    } else {
        $output .= __('You are already logged in');
    }
    return $output;
}