public/wordpress/wp-content/plugins/wp-courseware/includes/legacy/functions.php
/**
 * The function called when a user receives a grade for a quiz, either when marked manually, or
 * when the question it automatically graded.
 *
 * Triggered by wpcw_quiz_graded.
 *
 * @since 1.0.0
 *
 * @param integer $userID The ID of the user to notify.
 * @param object  $quizDetails The details of the quiz.
 * @param integer $grade The grade that they've been given
 * @param string  $additionalDetail Any additional data to add to the message.
 */
The function called when a user receives a grade for a quiz, either when marked manually, or
when the question it automatically graded.





@param integer $userID The ID of the user to notify.
@param object  $quizDetails The details of the quiz.
@param integer $grade The grade that they've been given
@param string  $additionalDetail Any additional data to add to the message.
The function called when a user receives a grade for a quiz either when marked manually or when the question it automatically graded . @param integer $userID The ID of the user to notify . @param object $quizDetails The details of the quiz . @param integer $grade The grade that they ' ve been given @param string $additionalDetail Any additional data to add to the message .
function WPCW_actions_userQuizGraded_notifyUser( $userID, $quizDetails, $grade, $additionalDetail ) {
	if ( ! $userID || ! $quizDetails ) {
		return;
	}
	$unitParentData = WPCW_units_getAssociatedParentData( $quizDetails->parent_unit_id );
	if ( $unitParentData->email_quiz_grade_option == 'send_email' ) {
		$userDetails = get_userdata( $userID );
		$post = get_post( $quizDetails->parent_unit_id );
		if ( ! $post ) {
			return;
		}
		wp_set_current_user( $userID );
		$fe = new WPCW_UnitFrontend( $post );
		if ( ! $fe->check_unit_doesUnitHaveParentData() || ! $fe->check_user_canUserAccessCourse() ) {
			return;
		}
		$emailBody    = $unitParentData->email_quiz_grade_body;
		$tagList_Body = WPCW_email_getTagList( $emailBody );
		$emailBody    = WPCW_email_replaceTags_quizData( $fe, $tagList_Body, $emailBody, $additionalDetail );
		$emailSubject    = $unitParentData->email_quiz_grade_subject;
		$tagList_Subject = WPCW_email_getTagList( $emailSubject );
		$emailSubject    = WPCW_email_replaceTags_quizData( $fe, $tagList_Subject, $emailSubject, $additionalDetail );
		WPCW_email_sendEmail( $unitParentData,
			$userDetails, 
			$userDetails->user_email,
			$emailSubject,
			$emailBody
		);
	}
}
function WPCW_actions_userQuizGraded_notifyUser ( $ userID , $ quizDetails , $ grade , $ additionalDetail ) { if ( ! $ userID || ! $ quizDetails ) { return ; } $ unitParentData = WPCW_units_getAssociatedParentData ( $ quizDetails -> parent_unit_id ) ; if ( $ unitParentData -> email_quiz_grade_option == 'send_email' ) { $ userDetails = get_userdata ( $ userID ) ; $ post = get_post ( $ quizDetails -> parent_unit_id ) ; if ( ! $ post ) { return ; } wp_set_current_user ( $ userID ) ; $ fe = new WPCW_UnitFrontend ( $ post ) ; if ( ! $ fe -> check_unit_doesUnitHaveParentData ( ) || ! $ fe -> check_user_canUserAccessCourse ( ) ) { return ; } $ emailBody = $ unitParentData -> email_quiz_grade_body ; $ tagList_Body = WPCW_email_getTagList ( $ emailBody ) ; $ emailBody = WPCW_email_replaceTags_quizData ( $ fe , $ tagList_Body , $ emailBody , $ additionalDetail ) ; $ emailSubject = $ unitParentData -> email_quiz_grade_subject ; $ tagList_Subject = WPCW_email_getTagList ( $ emailSubject ) ; $ emailSubject = WPCW_email_replaceTags_quizData ( $ fe , $ tagList_Subject , $ emailSubject , $ additionalDetail ) ; WPCW_email_sendEmail ( $ unitParentData , $ userDetails , $ userDetails -> user_email , $ emailSubject , $ emailBody ) ; } }
The function called when a user receives a grade for a quiz, either when marked manually, or
 when the question it automatically graded.
The function called when a user receives a grade for a quiz either when marked manually or when the question it automatically graded .
// Need parent details to determine if we can send an email or not. // Check if admin wants user to have an email. // User details - for sending the email. // Need post object to create the notification. // Set current user before calling WPCW_UnitFrontend class // Initalise the unit details. Check we have access. // Do email body first // Then do subject line // Now send email // User who's done the completion