Filter uncanny-toolkit-pro

uo_ld_course_access_expires_on

Filters the course access expiration date for a user, course, or group.

add_filter( 'uo_ld_course_access_expires_on', $callback, 10, 4 );

Description

Filters the course access expiration date for users in groups. Developers can modify the expiration date based on user, course, and group relationships. Fires after initial expiration date calculation but before it's saved or displayed. Useful for custom group-based expiration logic.


Usage

add_filter( 'uo_ld_course_access_expires_on', 'your_function_name', 10, 4 );

Parameters

$expiration_date (mixed)
This parameter contains the calculated expiration date for the user's course access.
$user_id (mixed)
This parameter contains the calculated expiration date for the user's course access.
$course_id (mixed)
This parameter contains the ID of the user for whom course access expiration is being determined.
$group_id (mixed)
The `$course_id` parameter contains the ID of the course for which access expiration is being determined.

Return Value

The filtered value.


Examples

add_filter( 'uo_ld_course_access_expires_on', function( $expiration_date, $user_id, $course_id, $group_id ) {

	// Example: Extend expiration date by 7 days if it's a specific course
	if ( $course_id == 123 ) { // Replace 123 with the actual course ID
		// Check if the current expiration date is set and not empty
		if ( ! empty( $expiration_date ) ) {
			// Convert expiration_date to a DateTime object for easier manipulation
			$date_obj = new DateTime( "@{$expiration_date}" ); // Assuming $expiration_date is a timestamp
			// Add 7 days to the expiration date
			$date_obj->modify( '+7 days' );
			// Return the new expiration timestamp
			return $date_obj->getTimestamp();
		}
	}

	// Example: If no specific logic applies, return the original expiration date
	return $expiration_date;

}, 10, 4 );

Placement

This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.


Source Code

src/classes/learn-dash-group-expiration.php:1149

public static function ld_course_access_expires_on_func( $course_access_upto, $course_id, $user_id ) {
		// check if user has any groups
		$groups = learndash_get_users_group_ids( $user_id, true );
		// check if course is part of a group
		$course_groups = learndash_get_course_groups( $course_id, true );
		if ( empty( $groups ) || empty( $course_groups ) ) {
			return $course_access_upto;
		}
		// check if course is not part of user groups
		$matched_groups = array_intersect( $groups, $course_groups );
		if ( empty( $matched_groups ) ) {
			return $course_access_upto;
		}
		foreach ( $matched_groups as $group_id ) {
			$group_courses = learndash_group_enrolled_courses( $group_id, true );
			if ( empty( $group_courses ) ) {
				continue;
			}
			if ( ! in_array( $course_id, $group_courses, true ) ) {
				continue;
			}
			$expiration_date = get_post_meta( $group_id, 'uo-expiration-date', true );
			if ( ! empty( $expiration_date ) ) {
				$system_time        = time();
				$wp_time            = current_time( 'timestamp' ); //phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.Requested
				$offset             = $system_time - $wp_time;
				$course_access_upto = apply_filters( 'uo_ld_course_access_expires_on', strtotime( $expiration_date ) + $offset, $user_id, $course_id, $group_id );
			}
			break;
		}

		return $course_access_upto;
	}

Scroll to Top