Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cu 86cx9n6wg added option to prevent multiple email sent #2732

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion js/qsm-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -4394,11 +4394,24 @@ var QSM_Quiz_Broadcast_Channel;

}(jQuery));


function qsm_check_email_sent_option() {
if (jQuery('input[name="send_email"]').prop('checked') === true) {
jQuery('#check_already_sent_email input[name="check_already_sent_email"]').prop( 'disabled', false );
jQuery('#check_already_sent_email').show();
} else {
jQuery('#check_already_sent_email input[name="check_already_sent_email"]').prop( 'disabled', true );
jQuery('#check_already_sent_email').hide();
}
}
/**
* QSM - failed submission data table action
*/
(function ($) {
qsm_check_email_sent_option();
$(document).on('change', 'input[name="send_email"]', function (event) {
event.preventDefault();
qsm_check_email_sent_option();
});
function submit_failed_submission_action_notice( res ) {
if ( 'object' !== typeof res || null === res || undefined === res.message ) {
return false;
Expand Down
18 changes: 15 additions & 3 deletions php/classes/class-qsm-emails.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public static function send_emails( $transient_id ) {
if ( 0 == $email_send && ! empty( $default_email_content ) ) {
self::send_results_email( $response_data, $default_email_to, $default_email_subject, $default_email_content, $default_email_reply_to, $default_index );
}

delete_transient( 'qsm_already_sent_emails_' . $response_data['quiz_id'] );
remove_filter( 'wp_mail_content_type', 'mlw_qmn_set_html_content_type' );
}

Expand Down Expand Up @@ -266,13 +266,25 @@ public static function send_results_email( $response_data, $to, $subject, $conte
$attachments = apply_filters( 'qsm_admin_email_attachments', $attachments, $response_data );
}

$quiz_options = maybe_unserialize( $response_data['quiz_settings']['quiz_options'] );
// Check if email has already been sent to the user for this quiz
if ( isset( $quiz_options['check_already_sent_email'] ) && 1 == $quiz_options['check_already_sent_email'] ) {
$already_sent_emails = get_transient( 'qsm_already_sent_emails_' . $response_data['quiz_id'] );
}
$already_sent_emails = ! empty( $already_sent_emails ) ? $already_sent_emails : array();

// Cycle through each to email address and send the email.
foreach ( $to_array as $to_email ) {
if ( is_email( $to_email ) ) {
if ( is_email( $to_email ) && ! in_array( $to_email, $already_sent_emails ) ) {
$mailResult = wp_mail( $to_email, $subject, $content, $headers, $attachments );
if ( $mailResult ) {
do_action( 'qsm_after_sending_email', $response_data, $to_email, $subject );
}else {
// Add the email to the list of already sent emails for this quiz
if ( isset( $quiz_options['check_already_sent_email'] ) && 1 == $quiz_options['check_already_sent_email'] ) {
$already_sent_emails[] = $to_email;
set_transient( 'qsm_already_sent_emails_' . $response_data['quiz_id'], $already_sent_emails, 3600 );
}
} else {
$mlwQuizMasterNext->log_manager->add( 'There has been an error in wp_mail. Please check SMTP details mail not sending. Error Code: 0001', 0, 'error' );
}
}
Expand Down
10 changes: 10 additions & 0 deletions php/classes/class-qsm-install.php
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,16 @@ public function register_default_settings() {
),
'default' => 1,
),
'check_already_sent_email' => array(
'type' => 'checkbox',
'options' => array(
array(
'label' => __( 'Not send email if already sent', 'quiz-master-next' ),
'value' => 1,
),
),
'default' => 0,
),
),
'help' => '',
'option_tab' => 'quiz_submission',
Expand Down