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
Return Return
(int|false) False if the lesson is available. WP Post ID of the lesson if it is not.
Source Source
File: includes/functions/llms.functions.access.php
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 | 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 ; } |
Expand full source code Collapse full source code View on GitHub
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. |