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

		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.