LLMS_Student::delete_enrollment( int $product_id, string $trigger = 'any' )
Delete a student enrollment.
Contents
Description Description
See also See also
- `llms_delete_student_enrollment()`: 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) Only delete the student's enrollment if the original enrollment trigger matches the submitted value. "any" will remove regardless of enrollment trigger. Default "any".
Default value: 'any'
Return Return
(boolean) Whether or not the enrollment records have been successfully removed.
Source Source
File: includes/models/model.llms.student.php
} 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 ) ); $post_type = str_replace( 'llms_', '', get_post_type( $product_id ) ); // Run legacy action and trigger cascading unenrollments for membership relationships. if ( 'membership' === $post_type ) { // Users should be unenrolled from all courses they accessed through this membership. $this->remove_membership_level( $product_id, $new_status ); } /** * Trigger an action immediately following user unenrollment * * The dynamic portion of this hook, `{$post_type}` corresponds to the post type of the * `$product_id`. Note that any post type prefixed with `llms_` is stripped. For example * when triggered by a membership (`llms_membership`) the hook will be `llms_user_removed_from_membership`. * * @since 3.37.9 * * @param int $user_id WP_User ID of the student * @param int $product_id WP_Post ID of the product. * @param string $trigger Enrollment trigger. * @param string $new_status New enrollment status of the student after the unenrollment has taken place. */ do_action( "llms_user_removed_from_{$post_type}", $this->get_id(), $product_id, $trigger, $new_status ); return true; } } // Update was prevented. return false; } /** * Delete a student enrollment. * * @since 3.33.0 * @since 3.36.2 Added logic to physically remove from the membership level and remove enrollments data on related products. * @since 4.2.0 The `$enrollment_trigger` parameter was added to the `llms_user_enrollment_deleted` action hook. * * @see `llms_delete_student_enrollment()` calls this function without having to instantiate the LLMS_Student class first. * * @param int $product_id WP Post ID of the course or membership. * @param string $trigger Optional. Only delete the student's enrollment if the original enrollment trigger matches the submitted value. * "any" will remove regardless of enrollment trigger. Default "any". * @return bool Whether or not the enrollment records have been successfully removed. */ public function delete_enrollment( $product_id, $trigger = 'any' ) {
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
4.2.0 | The $enrollment_trigger parameter was added to the llms_user_enrollment_deleted action hook. |
3.36.2 | Added logic to physically remove from the membership level and remove enrollments data on related products. |
3.33.0 | Introduced. |