UserData::is_enrolled( $course,  $force_check = false )

Determine if enrolled to a course


Parameters

$course

(Required)

$force_check

(Optional) bool

Default value: false


Return

(bool|mixed|void)


Source

File: classes/UserData.php

	public function is_enrolled( $course, $force_check = false ) {
		$course = dozent_get_course( $course );

		if ( ! $this->user_id || ! $course->get_id() ) {
			return false;
		}

		$is_enrolled = false;

		if ( $force_check ) {
			global $wpdb;

			$course_id = $course->get_id();
			$user_id   = $this->user_id;

			$query = $wpdb->get_row( "SELECT * FROM {$wpdb->dozent_enrols} WHERE course_id = {$course_id} AND user_id = {$user_id} AND status = 'active' ORDER BY expired_at DESC " );

			if ( $query ) {
				if ( ! empty( $query->expired_at ) ) {
					if ( strtotime( $query->expired_at ) > dozent_time() ) {
						$is_enrolled = $query;
					}
				} else {
					$is_enrolled = $query;
				}
			}

		} else {
			$is_enrolled = in_array( $course->get_id(), $this->get_enrolled_course_ids() );
		}

		/**
		 * Filter the is enrolled return
		 *
		 * @since DozentLMS 1.0.0
		 *
		 * @param  bool  $is_enrolled  IS Enrolled
		 * @param  object  $course  Course Object
		 * @param  int  $user_id  User ID
		 */

		return apply_filters( 'user_data_is_course_enrolled', $is_enrolled, $course, $this->user_id );
	}


Changelog

Changelog
Version Description
DozentLMS 1.0.0 Introduced.