LLMS_Student::unenroll( int $product_id, string $trigger = 'any', string $new_status = 'expired' )
Remove a student from a LifterLMS course or membership
Contents
Description Description
See also See also
- llms_unenroll_student(): calls this function without having to instantiate the LLMS_Student class first
Parameters Parameters
- $product_id
-
(int) (Required) WordPress Post ID of the course or membership
- $trigger
-
(string) (Optional) only remove the student if the original enrollment trigger matches the submitted value "any" will remove regardless of enrollment trigger
Default value: 'any'
- $new_status
-
(string) (Optional) the value to update the new status with after removal is complete
Default value: 'expired'
Return Return
(boolean)
Source Source
File: includes/models/model.llms.student.php
public function unenroll( $product_id, $trigger = 'any', $new_status = 'expired' ) { // can only unenroll those are a currently enrolled if ( ! $this->is_enrolled( $product_id, 'all', false ) ) { return false; } // assume we can't unenroll $update = false; // if trigger is "any" we'll just unenroll regardless of the trigger if ( 'any' === $trigger ) { $update = true; } // End if(). else { $enrollment_trigger = $this->get_enrollment_trigger( $product_id ); // no enrollment trigger exists b/c pre 3.0.0 enrollment, unenroll the user if ( ! $enrollment_trigger ) { $update = apply_filters( 'lifterlms_legacy_unenrollment_action', true ); } // End if(). elseif ( $enrollment_trigger == $trigger ) { $update = true; } } // update if we can if ( $update ) { // update enrollment for the product if ( $this->insert_status_postmeta( $product_id, $new_status ) ) { // update the cache $this->cache_set( sprintf( 'enrollment_status_%d', $product_id ), $new_status ); $this->cache_delete( sprintf( 'date_enrolled_%d', $product_id ) ); $this->cache_delete( sprintf( 'date_updated_%d', $product_id ) ); // trigger actions based on product type switch ( get_post_type( $product_id ) ) { case 'course': do_action( 'llms_user_removed_from_course', $this->get_id(), $product_id ); break; case 'llms_membership': // also physically remove from the membership level & perform unenrollment // on related products $this->remove_membership_level( $product_id, $new_status ); do_action( 'llms_user_removed_from_membership_level', $this->get_id(), $product_id ); break; } return true; } } // return false if we didn't update return false; }
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
3.0.0 | Introduced. |
User Contributed Notes User Contributed Notes
Permalink: