llms_is_post_restricted_by_drip_settings( int $post_id, int|null $user_id = null )

Determine if a lesson/quiz is restricted by drip settings.


Parameters Parameters

$post_id

(int) (Required) WP Post ID of a lesson or quiz.

$user_id

(int|null) (Optional) WP User ID (will use get_current_user_id() if none supplied). Default null.

Default value: null


Top ↑

Return Return

(int|false) False if the lesson is available. WP Post ID of the lesson if it is not.


Top ↑

Source Source

File: includes/functions/llms.functions.access.php

function llms_is_post_restricted_by_drip_settings( $post_id, $user_id = null ) {

	$post_type = get_post_type( $post_id );

	switch ( $post_type ) {
		// If we're on a lesson, lesson id is the post id.
		case 'lesson':
			$lesson_id = $post_id;
			break;
		case 'llms_quiz':
			$quiz      = llms_get_post( $post_id );
			$lesson_id = $quiz->get( 'lesson_id' );
			if ( ! $lesson_id ) {
				return false;
			}
			break;
		default: // Don't pass other post types.
			return false;
	}

	$lesson  = new LLMS_Lesson( $lesson_id );
	$user_id = $user_id ?? get_current_user_id();
	/**
	 * Filters whether or not to bypass drip restrictions on completed lessons.
	 *
	 * @since 6.5.0
	 *
	 * @param boolean $drip_bypass Whether or not to bypass drip restrictions on completed lessons.
	 * @param int     $post_id     WP Post ID of a lesson or quiz potentially restricted by drip settings.
	 * @param int     $user_id     WP User ID.
	 */
	$drip_bypass  = apply_filters( 'llms_lesson_drip_bypass_if_completed', true, $post_id, $user_id );
	$is_available = ( $drip_bypass && $user_id && llms_is_complete( $user_id, $lesson_id, 'lesson' ) ) || $lesson->is_available();

	return $is_available ? false : $lesson_id;

}


Top ↑

Changelog Changelog

Changelog
Version Description
6.5.0 Improve code readability turning if-elseif into a switch-case. Bypass drip content restriction on already completed lessons.
3.37.10 Use strict comparison '===' in place of '=='.
3.16.11 Unknown.
3.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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