Last active
June 4, 2022 15:06
-
-
Save wpmudev-sls/1036c357651a0b8c58adda87e62e69de to your computer and use it in GitHub Desktop.
[Forminator] Sends Quiz Right Answers by Email
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: [Forminator] Sends Quiz Right Answers by Email | |
* Plugin URI: https://wpmudev.com/ | |
* Description: The default email sent by the Forminator doesn’t show the correct answers to the quizzes. It only shows the answer which was answered by the quiz taker. This plugin makes the right answers also be displayed. | |
* Author: Glauber Silva @ WPMUDEV | |
* Author URI: https://wpmudev.com/ | |
* Task: SLS-2027 | |
* License: GPLv2 or later | |
* | |
* @package WPMUDEV_Forminator_Sends_Quiz_Right_Answers_by_Email | |
*/ | |
defined( 'ABSPATH' ) || exit; | |
function wpmudev_forminator_intercept_quiz_answers( $message, $quiz, $data ){ | |
foreach ( $data['entry'] as $key => $value ) { | |
if ( $value['isCorrect'] ) { | |
$old = '<li><b>Question : </b>' . esc_html( $data['entry'][ $key ]['question'] ) . '</li>' . PHP_EOL . | |
'<li><b>Answer : </b>' . esc_html( $data['entry'][ $key ]['answer'] ) . '</li>'; | |
$new = '<li><b>Question : </b>' . esc_html( $data['entry'][ $key ]['question'] ) . '</li>' . PHP_EOL . | |
'<li><b>Answer : </b>' . esc_html( $data['entry'][ $key ]['answer'] ) . ' - ✅ Right</li>'; | |
$message = str_replace( $old, $new, $message ); | |
} else { | |
foreach ( $quiz->questions[ $key ]['answers'] as $answer ) { | |
if ( isset( $answer['toggle'] ) && $answer['toggle'] ) { | |
$old = '<li><b>Question : </b>' . esc_html( $data['entry'][ $key ]['question'] ) . '</li>' . PHP_EOL . | |
'<li><b>Answer : </b>' . esc_html( $data['entry'][ $key ]['answer'] ) . '</li>'; | |
$new = '<li><b>Question : </b>' . esc_html( $data['entry'][ $key ]['question'] ) . '</li>' . PHP_EOL . | |
'<li><b>Answer : </b>' . esc_html( $data['entry'][ $key ]['answer'] ) . ' - ❌ Wrong (The right answer is: ' . esc_html( $answer['title'] ) . ')</li>'; | |
$message = str_replace( $old, $new, $message ); | |
} | |
} | |
} | |
} | |
return $message; | |
} | |
add_filter( 'forminator_quiz_mail_admin_message', 'wpmudev_forminator_intercept_quiz_answers', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment