public/wordpress/wp-content/plugins/wp-courseware/includes/legacy/functions.php
/**
 * Function called when the user completes a unit.
 *
 * @since 1.0.0
 *
 * @param integer $userID The ID of the user that's completed the unit.
 * @param integer $unitID The ID of the unit that's been completed.
 * @param object  $unitParentData The object of parent data associated with the unit, such as module and course.
 */
Function called when the user completes a unit.

@param integer $userID The ID of the user that's completed the unit.
@param integer $unitID The ID of the unit that's been completed.
@param object  $unitParentData The object of parent data associated with the unit, such as module and course.
Function called when the user completes a unit . @param integer $userID The ID of the user that ' s completed the unit . @param integer $unitID The ID of the unit that ' s been completed . @param object $unitParentData The object of parent data associated with the unit such as module and course .
function WPCW_actions_users_unitCompleted( $userID, $unitID, $unitParentData ) {
	if ( ! $userID || ! $unitID || ! $unitParentData ) {
		return;
	}
	global $wpdb, $wpcwdb;
	$wpdb->show_errors();
	WPCW_users_updateUserUnitProgress( $unitParentData->course_id, $userID, $unitParentData->course_unit_count );
	$userProgress = new WPCW_UserProgress( $unitParentData->course_id, $userID );
	$hasCourseCompleted = $userProgress->isCourseCompleted();
	if ( $userProgress->isModuleCompleted( $unitID ) && ! $hasCourseCompleted ) {
		do_action( 'wpcw_user_completed_module', $userID, $unitID, $unitParentData );
	}
	if ( $hasCourseCompleted ) {
		do_action( 'wpcw_user_completed_course', $userID, $unitID, $unitParentData );
	}
	$userDetails = get_userdata( $userID );
	$adminSubject = __( "Unit Complete Notification - {USER_NAME} - {UNIT_TITLE}", 'wp-courseware' );
	$adminBody = __( "Hi Admin!
Just to let you know, {USER_NAME} has just completed '{UNIT_TITLE}'.
{SITE_NAME}
{SITE_URL}", 'wp-courseware' );
	if ( $unitParentData->email_complete_unit_option_admin === 'send_email' && $unitParentData->course_to_email ) {
		WPCW_email_sendEmail( $unitParentData, $userDetails, $unitParentData->course_to_email, $adminSubject, $adminBody );
	}
	if ( $unitParentData->email_complete_unit_option === 'send_email' ) {
		$adminSubject = $unitParentData->email_complete_unit_subject;
		$adminBody    = $unitParentData->email_complete_unit_body;
		WPCW_email_sendEmail( $unitParentData, $userDetails, $userDetails->user_email, $unitParentData->email_complete_unit_subject, $unitParentData->email_complete_unit_body );
	}
	do_action( 'wpcw_user_completed_unit_notification', $unitParentData, $userDetails, $adminSubject, $adminBody );
}
function WPCW_actions_users_unitCompleted ( $ userID , $ unitID , $ unitParentData ) { if ( ! $ userID || ! $ unitID || ! $ unitParentData ) { return ; } global $ wpdb , $ wpcwdb ; $ wpdb -> show_errors ( ) ; WPCW_users_updateUserUnitProgress ( $ unitParentData -> course_id , $ userID , $ unitParentData -> course_unit_count ) ; $ userProgress = new WPCW_UserProgress ( $ unitParentData -> course_id , $ userID ) ; $ hasCourseCompleted = $ userProgress -> isCourseCompleted ( ) ; if ( $ userProgress -> isModuleCompleted ( $ unitID ) && ! $ hasCourseCompleted ) { do_action ( 'wpcw_user_completed_module' , $ userID , $ unitID , $ unitParentData ) ; } if ( $ hasCourseCompleted ) { do_action ( 'wpcw_user_completed_course' , $ userID , $ unitID , $ unitParentData ) ; } $ userDetails = get_userdata ( $ userID ) ; $ adminSubject = __ ( " Unit Complete Notification - {USER_NAME} - {UNIT_TITLE} " , 'wp-courseware' ) ; $ adminBody = __ ( " Hi Admin!

Just to let you know, {USER_NAME} has just completed '{UNIT_TITLE}'.

{SITE_NAME}
{SITE_URL} " , 'wp-courseware' ) ; if ( $ unitParentData -> email_complete_unit_option_admin === 'send_email' && $ unitParentData -> course_to_email ) { WPCW_email_sendEmail ( $ unitParentData , $ userDetails , $ unitParentData -> course_to_email , $ adminSubject , $ adminBody ) ; } if ( $ unitParentData -> email_complete_unit_option === 'send_email' ) { $ adminSubject = $ unitParentData -> email_complete_unit_subject ; $ adminBody = $ unitParentData -> email_complete_unit_body ; WPCW_email_sendEmail ( $ unitParentData , $ userDetails , $ userDetails -> user_email , $ unitParentData -> email_complete_unit_subject , $ unitParentData -> email_complete_unit_body ) ; } do_action ( 'wpcw_user_completed_unit_notification' , $ unitParentData , $ userDetails , $ adminSubject , $ adminBody ) ; }
Function called when the user completes a unit.
Function called when the user completes a unit .
// Update the user progress count. // Work out if module/course completed. // Cache result of course completion // Module is complete, but course isn't yet complete // Course has also completed // Get User Details. // Admin Subject. // Admin Body. // Admin wants an email notification, and email address exists. Assumption is that it's valid. // Check if admin wants user to have an email.