function course_signup($atts)
        {
            ob_start();
            $allowed = array('signup', 'login');
            extract(shortcode_atts(array('page' => isset($_REQUEST['page']) ? $_REQUEST['page'] : '', 'failed_login_text' => __('Invalid login.', 'cp'), 'failed_login_class' => 'red', 'logout_url' => '', 'signup_tag' => 'h3', 'signup_title' => __('Signup', 'cp'), 'login_tag' => 'h3', 'login_title' => __('Login', 'cp'), 'signup_url' => '', 'login_url' => '', 'redirect_url' => ''), $atts, 'course_signup'));
            $failed_login_text = sanitize_text_field($failed_login_text);
            $failed_login_class = sanitize_html_class($failed_login_class);
            $logout_url = esc_url_raw($logout_url);
            $signup_tag = sanitize_html_class($signup_tag);
            $signup_title = sanitize_text_field($signup_title);
            $login_tag = sanitize_html_class($login_tag);
            $login_title = sanitize_text_field($login_title);
            $signup_url = esc_url_raw($signup_url);
            $redirect_url = esc_url_raw($redirect_url);
            $page = in_array($page, $allowed) ? $page : 'signup';
            $signup_prefix = empty($signup_url) ? '&' : '?';
            $login_prefix = empty($login_url) ? '&' : '?';
            $signup_url = empty($signup_url) ? CoursePress::instance()->get_signup_slug(true) : $signup_url;
            $login_url = empty($login_url) ? CoursePress::instance()->get_login_slug(true) : $login_url;
            if (!empty($redirect_url)) {
                $signup_url = $signup_url . $signup_prefix . 'redirect_url=' . urlencode($redirect_url);
                $login_url = $login_url . $login_prefix . 'redirect_url=' . urlencode($redirect_url);
            }
            if (!empty($_POST['redirect_url'])) {
                $signup_url = CoursePress::instance()->get_signup_slug(true) . '?redirect_url=' . $_POST['redirect_url'];
                $login_url = CoursePress::instance()->get_login_slug(true) . '?redirect_url=' . $_POST['redirect_url'];
            }
            //Set a cookie now to see if they are supported by the browser.
            setcookie(TEST_COOKIE, 'WP Cookie check', 0, COOKIEPATH, COOKIE_DOMAIN);
            if (SITECOOKIEPATH != COOKIEPATH) {
                setcookie(TEST_COOKIE, 'WP Cookie check', 0, SITECOOKIEPATH, COOKIE_DOMAIN);
            }
            //Set a redirect for the logout form
            if (!empty($logout_url)) {
                update_option('cp_custom_login_url', $logout_url);
            }
            $form_message = '';
            $form_message_class = '';
            // Attempt a login if submitted
            if (isset($_POST['log']) && isset($_POST['pwd'])) {
                $auth = wp_authenticate_username_password(null, $_POST['log'], $_POST['pwd']);
                if (!is_wp_error($auth)) {
                    // if( defined('DOING_AJAX') && DOING_AJAX ) { cp_write_log('doing ajax'); }
                    $user = get_user_by('login', $_POST['log']);
                    $user_id = $user->ID;
                    wp_set_current_user($user_id);
                    wp_set_auth_cookie($user_id);
                    if (!empty($redirect_url)) {
                        wp_redirect(urldecode($redirect_url));
                    } else {
                        wp_redirect(CoursePress::instance()->get_student_dashboard_slug(true));
                    }
                    exit;
                } else {
                    $form_message = $failed_login_text;
                    $form_message_class = $failed_login_class;
                }
            }
            switch ($page) {
                case 'signup':
                    if (!is_user_logged_in()) {
                        if (cp_user_can_register()) {
                            ?>

							<?php 
                            $form_message_class = '';
                            $form_message = '';
                            $student = new Student(0);
                            if (isset($_POST['student-settings-submit'])) {
                                check_admin_referer('student_signup');
                                $min_password_length = apply_filters('coursepress_min_password_length', 6);
                                $student_data = array();
                                $form_errors = 0;
                                do_action('coursepress_before_signup_validation');
                                if ($_POST['username'] != '' && $_POST['first_name'] != '' && $_POST['last_name'] != '' && $_POST['email'] != '' && $_POST['password'] != '' && $_POST['password_confirmation'] != '') {
                                    if (!username_exists($_POST['username'])) {
                                        if (!email_exists($_POST['email'])) {
                                            if ($_POST['password'] == $_POST['password_confirmation']) {
                                                if (!preg_match("#[0-9]+#", $_POST['password']) || !preg_match("#[a-zA-Z]+#", $_POST['password']) || strlen($_POST['password']) < $min_password_length) {
                                                    $form_message = sprintf(__('Your password must be at least %d characters long and have at least one letter and one number in it.', 'cp'), $min_password_length);
                                                    $form_message_class = 'red';
                                                    $form_errors++;
                                                } else {
                                                    if ($_POST['password_confirmation']) {
                                                        $student_data['user_pass'] = $_POST['password'];
                                                    } else {
                                                        $form_message = __("Passwords don't match", 'cp');
                                                        $form_message_class = 'red';
                                                        $form_errors++;
                                                    }
                                                }
                                            } else {
                                                $form_message = __('Passwords don\'t match', 'cp');
                                                $form_message_class = 'red';
                                                $form_errors++;
                                            }
                                            $student_data['role'] = 'student';
                                            $student_data['user_login'] = $_POST['username'];
                                            $student_data['user_email'] = $_POST['email'];
                                            $student_data['first_name'] = $_POST['first_name'];
                                            $student_data['last_name'] = $_POST['last_name'];
                                            if (!is_email($_POST['email'])) {
                                                $form_message = __('E-mail address is not valid.', 'cp');
                                                $form_message_class = 'red';
                                                $form_errors++;
                                            }
                                            if (isset($_POST['tos_agree'])) {
                                                if ($_POST['tos_agree'] == '0') {
                                                    $form_message = __('You must agree to the Terms of Service in order to signup.', 'cp');
                                                    $form_message_class = 'red';
                                                    $form_errors++;
                                                }
                                            }
                                            if ($form_errors == 0) {
                                                if ($student_id = $student->add_student($student_data) !== 0) {
                                                    //$form_message = __( 'Account created successfully! You may now <a href="' . ( get_option( 'use_custom_login_form', 1 ) ? trailingslashit( site_url() . '/' . $this->get_login_slug() ) : wp_login_url() ) . '">log into your account</a>.', 'cp' );
                                                    //$form_message_class = 'regular';
                                                    $email_args['email_type'] = 'student_registration';
                                                    $email_args['student_id'] = $student_id;
                                                    $email_args['student_email'] = $student_data['user_email'];
                                                    $email_args['student_first_name'] = $student_data['first_name'];
                                                    $email_args['student_last_name'] = $student_data['last_name'];
                                                    $email_args['student_username'] = $student_data['user_login'];
                                                    $email_args['student_password'] = $student_data['user_pass'];
                                                    coursepress_send_email($email_args);
                                                    $creds = array();
                                                    $creds['user_login'] = $student_data['user_login'];
                                                    $creds['user_password'] = $student_data['user_pass'];
                                                    $creds['remember'] = true;
                                                    $user = wp_signon($creds, false);
                                                    if (is_wp_error($user)) {
                                                        $form_message = $user->get_error_message();
                                                        $form_message_class = 'red';
                                                    }
                                                    // if( defined('DOING_AJAX') && DOING_AJAX ) { cp_write_log('doing ajax'); }
                                                    if (isset($_POST['course_id']) && is_numeric($_POST['course_id'])) {
                                                        $course = new Course($_POST['course_id']);
                                                        wp_redirect($course->get_permalink());
                                                    } else {
                                                        if (!empty($redirect_url)) {
                                                            wp_redirect(apply_filters('coursepress_redirect_after_signup_redirect_url', $redirect_url));
                                                        } else {
                                                            wp_redirect(apply_filters('coursepress_redirect_after_signup_url', CoursePress::instance()->get_student_dashboard_slug(true)));
                                                        }
                                                    }
                                                    exit;
                                                } else {
                                                    $form_message = __('An error occurred while creating the account. Please check the form and try again.', 'cp');
                                                    $form_message_class = 'red';
                                                }
                                            }
                                        } else {
                                            $form_message = __('Sorry, that email address is already used!', 'cp');
                                            $form_message_class = 'error';
                                        }
                                    } else {
                                        $form_message = __('Username already exists. Please choose another one.', 'cp');
                                        $form_message_class = 'red';
                                    }
                                } else {
                                    $form_message = __('All fields are required.', 'cp');
                                    $form_message_class = 'red';
                                }
                            } else {
                                $form_message = __('All fields are required.', 'cp');
                            }
                            ?>
							<?php 
                            //ob_start();
                            if (!empty($signup_title)) {
                                echo '<' . $signup_tag . '>' . $signup_title . '</' . $signup_tag . '>';
                            }
                            ?>

							<p class="form-info-<?php 
                            echo apply_filters('signup_form_message_class', sanitize_text_field($form_message_class));
                            ?>
"><?php 
                            echo apply_filters('signup_form_message', sanitize_text_field($form_message));
                            ?>
</p>

							<?php 
                            do_action('coursepress_before_signup_form');
                            ?>

							<form id="student-settings" name="student-settings" method="post" class="student-settings">

								<?php 
                            do_action('coursepress_before_all_signup_fields');
                            ?>

								<input type="hidden" name="course_id" value="<?php 
                            esc_attr_e(isset($_GET['course_id']) ? $_GET['course_id'] : ' ');
                            ?>
"/>
								<input type="hidden" name="redirect_url" value="<?php 
                            echo $redirect_url;
                            ?>
"/>

								<label>
									<?php 
                            _e('First Name', 'cp');
                            ?>
:
									<input type="text" name="first_name" value="<?php 
                            echo isset($_POST['first_name']) ? $_POST['first_name'] : '';
                            ?>
"/>
								</label>

								<?php 
                            do_action('coursepress_after_signup_first_name');
                            ?>

								<label>
									<?php 
                            _e('Last Name', 'cp');
                            ?>
:
									<input type="text" name="last_name" value="<?php 
                            echo isset($_POST['last_name']) ? $_POST['last_name'] : '';
                            ?>
"/>
								</label>

								<?php 
                            do_action('coursepress_after_signup_last_name');
                            ?>

								<label>
									<?php 
                            _e('Username', 'cp');
                            ?>
:
									<input type="text" name="username" value="<?php 
                            echo isset($_POST['username']) ? $_POST['username'] : '';
                            ?>
"/>
								</label>

								<?php 
                            do_action('coursepress_after_signup_username');
                            ?>

								<label>
									<?php 
                            _e('E-mail', 'cp');
                            ?>
:
									<input type="text" name="email" value="<?php 
                            echo isset($_POST['email']) ? $_POST['email'] : '';
                            ?>
"/>
								</label>

								<?php 
                            do_action('coursepress_after_signup_email');
                            ?>

								<label>
									<?php 
                            _e('Password', 'cp');
                            ?>
:
									<input type="password" name="password" value=""/>
								</label>

								<?php 
                            do_action('coursepress_after_signup_password');
                            ?>

								<label class="right">
									<?php 
                            _e('Confirm Password', 'cp');
                            ?>
:
									<input type="password" name="password_confirmation" value=""/>
								</label>
								<br clear="both"/><br/>

								<?php 
                            if (shortcode_exists('signup-tos')) {
                                if (get_option('show_tos', 0) == '1') {
                                    ?>
										<label class="full"><?php 
                                    echo do_shortcode('[signup-tos]');
                                    ?>
</label>
									<?php 
                                }
                            }
                            ?>

								<?php 
                            do_action('coursepress_after_all_signup_fields');
                            ?>

								<label class="full">
									<?php 
                            printf(__('Already have an account? %s%s%s!', 'cp'), '<a href="' . $login_url . '">', __('Login to your account', 'cp'), '</a>');
                            ?>
								</label>

								<label class="full-right">
									<input type="submit" name="student-settings-submit" class="apply-button-enrolled" value="<?php 
                            _e('Create an Account', 'cp');
                            ?>
"/>
								</label>

								<?php 
                            do_action('coursepress_after_submit');
                            ?>

								<?php 
                            wp_nonce_field('student_signup');
                            ?>
							</form>
							<div class="clearfix" style="clear: both;"></div>

							<?php 
                            do_action('coursepress_after_signup_form');
                            ?>
							<?php 
                            //$content = ob_get_clean();
                            // Return the html in the buffer.
                            //return $content;
                        } else {
                            _e('Registrations are not allowed.', 'cp');
                        }
                    } else {
                        if (!empty($redirect_url)) {
                            wp_redirect(urldecode($redirect_url));
                        } else {
                            wp_redirect(CoursePress::instance()->get_student_dashboard_slug(true));
                        }
                        exit;
                    }
                    break;
                case 'login':
                    ?>
					<?php 
                    if (!empty($login_title)) {
                        echo '<' . $login_tag . '>' . $login_title . '</' . $login_tag . '>';
                    }
                    ?>
					<p class="form-info-<?php 
                    echo apply_filters('signup_form_message_class', sanitize_text_field($form_message_class));
                    ?>
"><?php 
                    echo apply_filters('signup_form_message', sanitize_text_field($form_message));
                    ?>
</p>
					<?php 
                    do_action('coursepress_before_login_form');
                    ?>
					<form name="loginform" id="student-settings" class="student-settings" method="post">
						<?php 
                    do_action('coursepress_after_start_form_fields');
                    ?>

						<label>
							<?php 
                    _e('Username', 'cp');
                    ?>
:
							<input type="text" name="log" value="<?php 
                    echo isset($_POST['log']) ? $_POST['log'] : '';
                    ?>
"/>
						</label>

						<label>
							<?php 
                    _e('Password', 'cp');
                    ?>
:
							<input type="password" name="pwd" value="<?php 
                    echo isset($_POST['pwd']) ? $_POST['pwd'] : '';
                    ?>
"/>
						</label>

						<?php 
                    do_action('coursepress_form_fields');
                    ?>

						<label class="full">
							<?php 
                    if (cp_user_can_register()) {
                        printf(__('Don\'t have an account? %s%s%s now!', 'cp'), '<a href="' . $signup_url . '">', __('Create an Account', 'cp'), '</a>');
                    }
                    ?>
						</label>

						<label class="half-left">
							<a href="<?php 
                    echo wp_lostpassword_url();
                    ?>
"><?php 
                    _e('Forgot Password?', 'cp');
                    ?>
</a>
						</label>
						<label class="half-right">
							<input type="submit" name="wp-submit" id="wp-submit" class="apply-button-enrolled" value="<?php 
                    _e('Log In', 'cp');
                    ?>
"><br>
						</label>
						<br clear="all"/>

						<input name="redirect_to" value="<?php 
                    echo CoursePress::instance()->get_student_dashboard_slug(true);
                    ?>
" type="hidden">
						<input name="testcookie" value="1" type="hidden">
						<input name="course_signup_login" value="1" type="hidden">
						<?php 
                    do_action('coursepress_before_end_form_fields');
                    ?>
					</form>

					<?php 
                    do_action('coursepress_after_login_form');
                    ?>
					<?php 
                    break;
            }
            $content = ob_get_clean();
            // Return the html in the buffer.
            return $content;
        }
 function signup_create_user()
 {
     // cp_write_log( 'creating user....' );
     parse_str($_POST['data'], $posted_data);
     if (wp_verify_nonce($posted_data['submit_signup_data'], 'popup_signup_nonce')) {
         $student = new Student(0);
         $student_data = array();
         $student_data['role'] = get_option('default_role', 'subscriber');
         $student_data['user_login'] = $posted_data['username'];
         $student_data['user_pass'] = $posted_data['cp_popup_password'];
         $student_data['user_email'] = $posted_data['email'];
         $student_data['first_name'] = $posted_data['student_first_name'];
         $student_data['last_name'] = $posted_data['student_last_name'];
         $student_id = $student->add_student($student_data);
         if ($student_id !== 0) {
             $email_args['email_type'] = 'student_registration';
             $email_args['student_id'] = $student_id;
             $email_args['student_email'] = $student_data['user_email'];
             $email_args['student_first_name'] = $student_data['first_name'];
             $email_args['student_last_name'] = $student_data['last_name'];
             $email_args['student_username'] = $student_data['user_login'];
             $email_args['student_password'] = $student_data['user_pass'];
             coursepress_send_email($email_args);
             $creds = array();
             $creds['user_login'] = $student_data['user_login'];
             $creds['user_password'] = $student_data['user_pass'];
             $creds['remember'] = true;
             $user = wp_signon($creds, false);
             $args['student_id'] = $student_id;
             $args['course_id'] = $posted_data['course_id'];
             $this->popup_signup('enrollment', $args);
             exit;
         }
     }
 }
     $form_message = __("Passwords don't match", 'cp');
     $form_message_class = 'error';
     $form_errors++;
 }
 //$student_data['role'] = 'student';
 $student_data['user_login'] = $_POST['username'];
 $student_data['user_email'] = $_POST['email'];
 $student_data['first_name'] = $_POST['first_name'];
 $student_data['last_name'] = $_POST['last_name'];
 if (!is_email($_POST['email'])) {
     $form_message = __('E-mail address is not valid.', 'cp');
     $form_message_class = 'error';
     $form_errors++;
 }
 if ($form_errors == 0) {
     if ($student_id = $student->add_student($student_data) !== 0) {
         $global_option = !is_multisite();
         update_user_option($student_id, 'role', 'student', $global_option);
         $form_message = __('Account created successfully!', 'cp');
         $form_message_class = 'updated';
         /* $email_args['email_type'] = 'student_registration';
         	  $email_args['student_id'] = $student_id;
         	  $email_args['student_email'] = $student_data['user_email'];
         	  $email_args['student_first_name'] = $student_data['first_name'];
         	  $email_args['student_last_name'] = $student_data['last_name'];
         	  coursepress_send_email( $email_args ); */
     } else {
         $form_message = __('An error occured while creating the account. Please check the form and try again.', 'cp');
         $form_message_class = 'error';
     }
 }
Example #4
0
    {
        echo "{$var} students.";
    }
}
echo Student::$total_students;
Student::$total_students = 13;
echo "<br>";
echo Student::$total_students;
echo "<br>";
echo Student::welcome_students();
echo "<br>";
Student::add_student();
// 14
Student::add_student();
// 15
Student::add_student();
// 16 $total_students
echo Student::$total_students;
echo "<br>";
// static variable are the php version of class variables. These will go with
// all instances of the classes. As well these variables can be accessed
// without declaring an instance of the class at all. Therefore I do not need
// to go `$x = new ClassName();`
//
// However to access the static variables I use the :: instead of the ->
//
// In python these had a much subtler difference as the instance version was
// called `self.VARIABLE` and the class version got declare like normal.
// Recall having to be carefully in python with making mutable objects as
// class variables like a list and dicts.
//