ld_lesson_access_from__visible_after

apply_filters( 'ld_lesson_access_from__visible_after',  int $lesson_access_from,  int $lesson_id,  int $user_id )

Filters the timestamp of when lesson will be visible after.


Description #


Parameters #

$lesson_access_from

(int) The timestamp of when the lesson will be available after a specific date.

$lesson_id

(int) Lesson ID.

$user_id

(int) User ID.


Source #

File: includes/course/ld-course-functions.php


Examples #

 <?php
/**
 * Example usage for ld_lesson_access_from__visible_after filter.
 */
add_filter(
	'ld_lesson_access_from__visible_after',
	function ( $gmt_timestamp = 0, $lesson_id = 0, $user_id = 0 ) {

		// Check to ensure our timestamp is not empty
		if ( ! empty( $gmt_timestamp ) ) {

			// Example 1: In this example we want to remove hh:mm:ss: values from the timestamp so the user gets access at midnight.
			// Let's assume for the purpose of this example you have a lesson using the 'Make lesson visible X days after sign-up' option with a value
			// if '1'. A student started the course on 2017-02-18 02:34pm. This would mean with the '1' value they will get access to the lesson one
			// day (24 hours) later on 2017-02-19 02:34pm.
			// But assume you don't want the user to have to wait 24 hours. You want the user do get access at the start of the next day 2017-02-19 (midnight)

			// The logic below is how this can be done.

			// Then convert to YMD format.
			$gmt_ymd = date( 'Y-m-d H:i:s', $gmt_timestamp );

			// At this point $gmt_ymd is still GMT so we need to adjust it to our local timezone. To do
			// we use the WP utility function get_date_from_gmt(). But instead of converting the
			// hour/minute/seconds to local we want to set these to 00:00:00 so the time is midnight
			$gmt_local_midnight = get_date_from_gmt( $gmt_ymd, 'Y-m-d 00:00:00' );

			// so noy we have a nice human readable value in $gmt_local_midnight
			// that will be something like '2017-02-15 00:00:00'.

			// We now need to return a timestamp (not YMD) back to LD. So we need to convert the YMD
			// date back into a timestamp
			$gmt_timestamp = learndash_get_timestamp_from_date_string( $gmt_local_midnight, true );
		}

		// Always return the $gmt_timestamp.
		return $gmt_timestamp;

	},
	10,
	3
);