CourseGate::enter_course()


Source

File: classes/CourseGate.php

	public function enter_course() {
		dozent_checking_nonce();

		$course_id = (int) dozent_input_text( 'course_id' );

		/**
		 * Main course gate action hook, it will fire most first when any user try to enter / buy course
		 *
		 * @since DozentLMS 1.0.0
		 *
		 * @param  int  $course_id  Course ID
		 */

		do_action( 'dozent_course_gate_before', $course_id );

		$course    = dozent_get_course( $course_id );
		$start_uri = $course->start_uri();

		//If Public, send him to direct course start page
		if ( $course->is_public() ) {
			dozent_redirect( $start_uri );
		}

		/**
		 * Filter the auto enrol decision
		 *
		 * @since DozentLMS 1.0.0
		 */

		$auto_enrol = apply_filters( 'dozent_course_auto_enrol_after_login', true );

		if ( ! is_user_logged_in() ) {

			$login_redirect_query_arg = [
				'course_id'              => $course_id,
				'redirected_after_login' => 1,
			];

			if ( $auto_enrol ) {
				$login_redirect_query_arg['auto_enrol'] = 1;
			}

			/**
			 * Filter the query arg after successfully login and redirect course URL
			 */

			$login_redirect_query_arg = (array) apply_filters( 'login_redirect_to_course_query_arg',
				$login_redirect_query_arg );

			if ( dozent_count( $login_redirect_query_arg ) ) {
				$start_uri = add_query_arg( $login_redirect_query_arg, $start_uri );
			}

			dozent_redirect( wp_login_url( $start_uri ) );
		}

		//If course is protected sent directory to course start page
		if ( $course->is_protected() ) {
			dozent_redirect( $start_uri );
		}

		$user = wp_get_current_user();

		if ( dozent_course_is_enrolled( $course, $user, true ) ) {

			dozent_redirect( $start_uri );

		} else{

			if ( $course->is_free() ) {
				$enrol_data = dozent_enrol_course( $course, $user );
				dozent_redirect( $start_uri );
			}

			if ( $course->is_closed() ) {
				//Close product required integration in order to complete enrolment

				/**
				 * Action hook to process course gate with integration
				 *
				 * @since DozentLMS 1.0.0
				 *
				 * @param object $course
				 */

				do_action( 'dozent_course_type_closed_gate', $course );

			}

		}

		do_action( 'dozent_course_gate_after', $course_id );
	}