LLMS_Student::enroll( int $product_id, string $trigger = 'unspecified' )
Enroll the student in a course or membership
Contents
Description Description
See also See also
- llms_enroll_student(): calls this function without having to instantiate the LLMS_Student class first
Parameters Parameters
- $product_id
-
(int) (Required) WP Post ID of the course or membership
- $trigger
-
(string) (Optional) String describing the reason for enrollment
Default value: 'unspecified'
Return Return
(boolean)
Source Source
File: includes/models/model.llms.student.php
public function enroll( $product_id, $trigger = 'unspecified' ) { do_action( 'before_llms_user_enrollment', $this->get_id(), $product_id ); // can only be enrolled in the following post types $product_type = get_post_type( $product_id ); if ( ! in_array( $product_type, array( 'course', 'llms_membership' ) ) ) { return false; } // check enrollment before enrolling // this will prevent duplicate enrollments if ( llms_is_user_enrolled( $this->get_id(), $product_id ) ) { return false; } // if the student has been previously enrolled, simply update don't run a full enrollment if ( $this->get_enrollment_status( $product_id, false ) ) { $insert = $this->insert_status_postmeta( $product_id, 'enrolled', $trigger ); } else { $insert = $this->insert_enrollment_postmeta( $product_id, $trigger ); } // add the user postmeta for the enrollment if ( ! empty( $insert ) ) { // update the cache $this->cache_set( sprintf( 'enrollment_status_%d', $product_id ), 'enrolled' ); $this->cache_delete( sprintf( 'date_enrolled_%d', $product_id ) ); $this->cache_delete( sprintf( 'date_updated_%d', $product_id ) ); // trigger additional actions based off post type switch ( get_post_type( $product_id ) ) { case 'course': do_action( 'llms_user_enrolled_in_course', $this->get_id(), $product_id ); break; case 'llms_membership': $this->add_membership_level( $product_id ); do_action( 'llms_user_added_to_membership_level', $this->get_id(), $product_id ); break; } return true; } return false; }
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
2.2.3 | Introduced. |
User Contributed Notes User Contributed Notes
Permalink: