Filter uncanny-toolkit-pro

uo_enable_mail_user_quiz_certificates

Filters whether to send an email certificate to the user after completing a quiz.

add_filter( 'uo_enable_mail_user_quiz_certificates', $callback, 10, 1 );

Description

Filters whether to email quiz certificates to users. Developers can return `false` to prevent emails from being sent. This hook fires just before the certificate email is composed and sent.


Usage

add_filter( 'uo_enable_mail_user_quiz_certificates', 'your_function_name', 10, 1 );

Parameters

$email_params (mixed)
This parameter is a boolean value that determines whether to enable the sending of quiz certificates via email.

Return Value

The filtered value.


Examples

/**
 * Conditionally disable sending quiz certificates via email based on user role.
 *
 * This filter allows administrators to prevent specific user roles from receiving
 * automated quiz certificate emails. In this example, users with the 'editor'
 * role will not receive certificates.
 *
 * @param bool   $enable_mail_user Whether to enable sending the email.
 * @param array  $email_params     An array of email parameters, including 'email', 'sub', 'msg', and potentially 'file'.
 * @return bool The modified value of $enable_mail_user.
 */
add_filter( 'uo_enable_mail_user_quiz_certificates', 'my_custom_disable_quiz_certificate_email', 10, 2 );

function my_custom_disable_quiz_certificate_email( $enable_mail_user, $email_params ) {
    // Check if the current user has the 'editor' role.
    if ( current_user_can( 'editor' ) ) {
        // If the user is an editor, disable sending the email.
        return false;
    }

    // Otherwise, keep the default behavior.
    return $enable_mail_user;
}

Placement

This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.


Source Code

src/classes/generate-p-d-f-email.php:274

$email_param_msg = $email_params['msg'];
		$email_param_msg = str_ireplace( '$quizname', $setup_parameters['quiz-name'], $email_param_msg );
		$email_param_msg = str_ireplace( '$userId', $user->ID, $email_param_msg );
		$email_param_msg = str_ireplace( '$username', $user->user_login, $email_param_msg );
		$email_param_msg = str_ireplace( '$result', $setup_parameters['result'] . '%', $email_param_msg );

		$enable_mail_user = apply_filters( 'uo_enable_mail_user_quiz_certificates', true, $email_params );
		if ( true === $enable_mail_user ) {
			wp_mail( $email_params['email'], $email_param_sub, wpautop( $email_param_msg ), $headers, $file );
		}

		if ( 'on' === $is_admin ) {
			$group_msg           = str_ireplace( '%Group Name%', $ugroups, $group_msg );
			$change_content_type = apply_filters( 'uo_apply_wp_mail_content_type', true );


Scroll to Top