LLMS_Lesson::get_available_date( string $format = '' )

Get the date a course became or will become available according to element drip settings


Description Description

If there are no drip settings, the published date of the element will be returned.


Top ↑

Parameters Parameters

$format

(string) (Optional) Date format (passed to date_i18n()). Default is empty string. When not specified the WP Core date + time formats will be used.

Default value: ''


Top ↑

Return Return

(string)


Top ↑

Source Source

File: includes/models/model.llms.lesson.php

	public function get_available_date( $format = '' ) {

		if ( ! $format ) {
			$format = get_option( 'date_format' ) . ' ' . get_option( 'time_format' );
		}

		$drip_method = $this->get( 'drip_method' );

		$days = $this->get( 'days_before_available' ) * DAY_IN_SECONDS;

		// Default availability is the element's post date.
		$available = $this->get_date( 'date', 'U' );

		switch ( $drip_method ) {

			// Available on a specific date / time.
			case 'date':
				$date = $this->get( 'date_available' );
				$time = $this->get( 'time_available' );

				if ( ! $time ) {
					$time = '12:00 AM';
				}

				$available = strtotime( $date . ' ' . $time );

				break;

			// Available # of days after enrollment in course.
			case 'enrollment':
				$student = llms_get_student();
				if ( $student ) {
					$available = $days + $student->get_enrollment_date( $this->get( 'parent_course' ), 'enrolled', 'U' );
				}
				break;

			case 'prerequisite':
				if ( $this->has_prerequisite() ) {
					$student = llms_get_student();
					if ( $student ) {
						$date = $student->get_completion_date( $this->get( 'prerequisite' ), 'U' );
						if ( $date ) {
							$available = $days + $date;
						}
					}
				}

				break;

			// Available # of days after course start date.
			case 'start':
				$course            = $this->get_course();
				$course_start_date = $course ? $course->get_date( 'start_date', 'U' ) : '';

				if ( $course_start_date ) {
					$available = $days + $course_start_date;
				}

				break;

		}

		return date_i18n( $format, $available );

	}


Top ↑

Changelog Changelog

Changelog
Version Description
5.7.0 Replaced the call to the deprecated LLMS_Lesson::get_parent_course() method with LLMS_Lesson::get( 'parent_course' ).
3.36.2 Add available number of days to the course start date only if there's a course start date.
3.16.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.