LLMS_AJAX_Handler::update_student_enrollment( array $request )
Add or remove a student from a course or membership.
Parameters Parameters
- $request
-
(array) (Required) $_POST data.
Return Return
((WP_Error|array))
Source Source
File: includes/class.llms.ajax.handler.php
if ( ! in_array( $request['status'], array( 'add', 'remove', 'delete' ), true ) ) {
return new WP_Error( 400, __( 'Invalid status', 'lifterlms' ) );
}
$student_id = intval( $request['student_id'] );
$post_id = intval( $request['post_id'] );
switch ( $request['status'] ) {
case 'add':
$res = llms_enroll_student( $student_id, $post_id, 'admin_' . get_current_user_id() );
break;
case 'remove':
$res = llms_unenroll_student( $student_id, $post_id, 'cancelled', 'any' );
break;
case 'delete':
$res = llms_delete_student_enrollment( $student_id, $post_id, 'any' );
break;
}
if ( ! $res ) {
// Translators: %s = action add|remove|delete.
return new WP_Error( 400, sprintf( __( 'Action "%1$s" failed. Please try again', 'lifterlms' ), $request['status'] ) );
}
return array(
'success' => true,
);
}
/**
* Validate a Coupon via the Checkout Form
*
* @since 3.0.0
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
| Version | Description |
|---|---|
| 3.37.14 | Use strict comparison. |
| 3.33.0 | Handle the delete enrollment request and make sure the $request['post_id'] is not empty. Also always return either a WP_Error on failure or a "success" array on action performed. |
| 3.0.0 | Introduced. |