learndash_quiz_email

apply_filters( 'learndash_quiz_email',  array $email_params,  WpProQuiz_Model_Quiz $quiz )

Filters quiz email parameters.


Description #


Parameters #

$email_params

(array) An array of quiz email parameters.

$quiz

(WpProQuiz_Model_Quiz) Quiz object.


Source #

File: includes/lib/wp-pro-quiz/lib/controller/WpProQuiz_Controller_Quiz.php


Examples #

 <?php
/**
 * Example usage for learndash_quiz_email filter.
 */
/**
 * Quiz email filter for User email message.
 */
add_filter(
	'learndash_quiz_email',
	function( $email_params = array() ) {
		$globalMapper = new WpProQuiz_Model_GlobalSettingsMapper();
		$userEmail    = $globalMapper->getUserEmailSettings();

		// If the email setting are using HTML we use WP to format the message.
		if ( ( isset( $userEmail['html'] ) ) && ( $userEmail['html'] ) ) {
			if ( ( isset( $email_params['msg'] ) ) && ( ! empty( $email_params['msg'] ) ) ) {
				$email_params['msg'] = wpautop( $email_params['msg'] );
			}
		}

		// Always return $email_params.
		return $email_params;
	},
	1
);

add_filter(
	'learndash_quiz_email',
	function ( $email_params = array(), WpProQuiz_Model_Quiz $quiz ) {
		$user = wp_get_current_user();

		$r                       = array(
			'$userId'   => $user->ID,
			'$username' => $user->display_name,
			'$quizname' => $quiz->getName(),
		);
		$email_params['subject'] = str_replace( array_keys( $r ), $r, $email_params['subject'] );

		// Always return $email_params
		return $email_params;

	},
	10,
	2
);