Hello @foxybrown ,
Please check this code:
<?php
add_filter( 'forminator_replace_quiz_form_data', 'wpmudev_show_quiz_result_with_pictures', 10, 4 );
function wpmudev_show_quiz_result_with_pictures( $content, $quiz, $data, $entry ){
if( $quiz->id!= 1356 ){ //Please change the quiz ID
return $content;
}
$result_behav = isset( $quiz->settings['results_behav'] ) ? $quiz->settings['results_behav'] : '';
if ( stripos( $content, '{quiz_answer_pic}' ) !== false && ( empty( $result_behav ) || 'end' === $result_behav ) ) {
$answer_content = PHP_EOL . '<ul>' . PHP_EOL;
$answers = isset( $data['answers'] ) ? $data['answers'] : array();
$question_ids = array();
if ( is_array( $answers ) ) {
foreach ( $answers as $question_id => $answer_id ) {
// In multi-answer, $question_id looks like this "question-2051-7608-3".
$question_id = preg_replace( '/(-\d+$)/', '', $question_id );
if ( ! in_array( $question_id, $question_ids ) ) {
$answer = $quiz->getAnswer( $question_id, $answer_id );
$answer_text = isset( $answer['title'] ) ? $answer['title'] : '';
if( $answer_text == '' ){
$answer_img = isset( $answer['image'] ) ? $answer['image'] : '';
$answer_text = '<img src='.$answer_img.' class="wpmudev-answer-img">';
}
$question_ids[ $question_id ][] = $answer_text;
}
}
foreach ( $question_ids as $question_id => $answer_titles ) {
$question = $quiz->getQuestion( $question_id );
$question_text = isset( $question['title'] ) ? $question['title'] : '';
$answer_head = count( $answer_titles ) > 1 ? esc_html__( 'Answers : ', 'forminator' ) : esc_html__( 'Answer : ', 'forminator' );
$answer_content .= '<li>' . PHP_EOL;
$answer_content .= '<ul>' . PHP_EOL;
$answer_content .= '<li><b>' . esc_html__( 'Question : ', 'forminator' ) . '</b>' . esc_html( $question_text ) . '</li>' . PHP_EOL;
$answer_content .= '<li><b>' . $answer_head . '</b>' . wp_kses_post( implode( ', ', $answer_titles ) ) . '</li>' . PHP_EOL;
$answer_content .= '</ul>' . PHP_EOL;
$answer_content .= '</li>' . PHP_EOL;
}
}
$answer_content .= '</ul>';
$content = str_ireplace( '{quiz_answer_pic}', $answer_content, $content );
}
return $content;
}
change the quiz ID in this line if( $quiz->id!= 1356 ){
.
After adding the snippet, {quiz_answer_pic} macro can be used in Behavior → Final Count Message .
Use this code as mu-plugin https://premium.wpmudev.org/docs/getting-started/download-wpmu-dev-plugins-themes/#installing-mu-plugins
kind regards,
Kasia