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.


Top ↑

Return Return

((WP_Error|array))


Top ↑

Source Source

File: includes/class.llms.ajax.handler.php

1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
    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


Top ↑

Changelog 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.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.