public/wordpress/wp-content/plugins/wp-courseware/includes/legacy/ajax.php
/**
 * Function called when the user is
 * enrolling via enrollment shortcode.
 *
 * @since 1.0.0
 */
Function called when the user is
enrolling via enrollment shortcode.


Function called when the user is enrolling via enrollment shortcode .
function WPCW_AJAX_course_handleEnrollment_button() {
	if ( ! wp_verify_nonce( WPCW_arrays_getValue( $_POST, 'enrollment_nonce' ), 'wpcw-enrollment-nonce' ) ) {
		die ( __( 'Security check failed!', 'wp-courseware' ) );
	}
	$courseList = WPCW_arrays_getValue( $_POST, 'id' );
	if ( ! preg_match( '/(\d+)(_\s*\d+)*/', $courseList, $matches ) ) {
		echo WPCW_UnitFrontend::message_error_getCompletionBox_error();
		die();
	}
	$courseIDs = explode( "_", $matches[0] );
	$user_id   = get_current_user_id();
	WPCW_courses_syncUserAccess( $user_id, $courseIDs, 'add' );
	foreach ( $courseIDs as $courseID ) {
		$course_id = $courseID;
		$courseDetails = WPCW_courses_getCourseDetails( $courseID );
				$userCourses = WPCW_courses_canUserAccessCourse( $courseID, $user_id );
		if ( $userCourses ) {
			$course_title = sprintf( __( '%s', 'wp-courseware' ), $courseDetails->course_title );
			$success_message = apply_filters( 'wpcw_course_enrollment_success_message', sprintf( __( 'Success! You have been enrolled into %s', 'wp-courseware' ), $course_title ), $course_id, $user_id );
			echo WPCW_UnitFrontend::message_createMessage_success( $success_message );
		} else {
			$error_message = apply_filters( 'wpcw_course_enrollment_error_message', __( 'Oops! Something went wrong. Please contact the course instructor for more information.', 'wp-courseware' ), $course_id, $user_id );
			echo WPCW_UnitFrontend::message_createMessage_error( $error_message );
		}
	}
	die();
}
function WPCW_AJAX_course_handleEnrollment_button ( ) { if ( ! wp_verify_nonce ( WPCW_arrays_getValue ( $ _POST , 'enrollment_nonce' ) , 'wpcw-enrollment-nonce' ) ) { die ( __ ( 'Security check failed!' , 'wp-courseware' ) ) ; } $ courseList = WPCW_arrays_getValue ( $ _POST , 'id' ) ; if ( ! preg_match ( '/(\d+)(_\s*\d+)*/' , $ courseList , $ matches ) ) { echo WPCW_UnitFrontend :: message_error_getCompletionBox_error ( ) ; die ( ) ; } $ courseIDs = explode ( " _ " , $ matches [ 0 ] ) ; $ user_id = get_current_user_id ( ) ; WPCW_courses_syncUserAccess ( $ user_id , $ courseIDs , 'add' ) ; foreach ( $ courseIDs as $ courseID ) { $ course_id = $ courseID ; $ courseDetails = WPCW_courses_getCourseDetails ( $ courseID ) ; $ userCourses = WPCW_courses_canUserAccessCourse ( $ courseID , $ user_id ) ; if ( $ userCourses ) { $ course_title = sprintf ( __ ( '%s' , 'wp-courseware' ) , $ courseDetails -> course_title ) ; $ success_message = apply_filters ( 'wpcw_course_enrollment_success_message' , sprintf ( __ ( 'Success! You have been enrolled into %s' , 'wp-courseware' ) , $ course_title ) , $ course_id , $ user_id ) ; echo WPCW_UnitFrontend :: message_createMessage_success ( $ success_message ) ; } else { $ error_message = apply_filters ( 'wpcw_course_enrollment_error_message' , __ ( 'Oops! Something went wrong. Please contact the course instructor for more information.' , 'wp-courseware' ) , $ course_id , $ user_id ) ; echo WPCW_UnitFrontend :: message_createMessage_error ( $ error_message ) ; } } die ( ) ; }
Function called when the user is
 enrolling via enrollment shortcode.
Function called when the user is enrolling via enrollment shortcode .
// Validate the course ID //if (!preg_match('/enroll-(\d+)(,\s*\d+)*/', $courseList, $matches)) { //if (!preg_match('/enroll-([^-]+)-([\d+,\d]+)/', $courseList, $matches)) { //enroll user into course(s) // verify enrollment // Back Compat // Get course details to fetch course title // Can the student access the course now?
 /**
			 * Filter: Course Enrollment Success Message.
			 *
			 * @since 4.3.0
			 *
			 * @param string $message The success message.
			 * @param int $course_id The course id.
			 * @param int $user_id The user id.
			 *
			 * @return string $message The success message modified.
			 */ /**
			 * Filter: Course Enrollment Error Message.
			 *
			 * @since 4.3.0
			 *
			 * @param string $message The success message.
			 * @param int $course_id The course id.
			 * @param int $user_id The user id.
			 *
			 * @return string $message The success message modified.
			 */