LLMS_Student::is_enrolled( int|array $product_ids = null, string $relation = 'all', bool $use_cache = true )
Determine if a student is enrolled in a Course or Membership.
Contents
Description Description
See also See also
Parameters Parameters
- $product_ids
-
(int|array) (Optional) WP Post ID of a Course, Section, Lesson, or Membership or array of multiple IDs.
Default value: null
- $relation
-
(string) (Optional) Comparator for enrollment check. All = user must be enrolled in all $product_ids. Any = user must be enrolled in at least one of the $product_ids.
Default value: 'all'
- $use_cache
-
(bool) (Optional) If true, returns cached data if available, if false will run a db query.
Default value: true
Return Return
(boolean)
Source Source
File: includes/models/model.llms.student.php
public function is_enrolled( $product_ids = null, $relation = 'all', $use_cache = true ) { // Assume enrollment unless we find otherwise. $ret = true; // Allow a single product ID to be submitted (backwards compat). $product_ids = ! is_array( $product_ids ) ? array( $product_ids ) : $product_ids; foreach ( $product_ids as $id ) { $enrolled = ( 'enrolled' === strtolower( $this->get_enrollment_status( $id, $use_cache ) ) ); // If use must be enrolled in all products and one is not enrolled: quit the loop & return false. if ( 'all' === $relation && ! $enrolled ) { $ret = false; break; // If user must be enrolled in any. } elseif ( 'any' === $relation ) { // If we find an enrollment: return true and quit the loop. if ( $enrolled ) { $ret = true; break; // If not switch return to false but keep looking. } else { $ret = false; } } } return apply_filters( 'llms_is_user_enrolled', $ret, $this, $product_ids, $relation, $use_cache ); }
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
3.0.0 | Introduced. |