Skip to content

Instantly share code, notes, and snippets.

@wpmudev-sls
Last active January 21, 2025 04:21
Show Gist options
  • Save wpmudev-sls/95a49d66c65be08404677acd8c60680c to your computer and use it in GitHub Desktop.
Save wpmudev-sls/95a49d66c65be08404677acd8c60680c to your computer and use it in GitHub Desktop.
[Forminator Pro] - Fix quiz result order issue in case of a tie
<?php
/**
* Plugin Name: [Forminator Pro] Quiz result order fix
* Description: Quiz result order fix in case of a tie.
* Author: Prashant @ WPMUDEV
* Task: SLS-6767
* Author URI: https://premium.wpmudev.org
* License: GPLv2 or later
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
add_action(
'wp_ajax_forminator_save_quiz_nowrong',
function () {
if ( ! isset( $_POST['data'] ) ) {
return;
}
$changed = false;
$quiz_data = json_decode( stripslashes( $_POST['data'] ), true );
if ( 47123 !== $quiz_data['settings']['form_id'] ) { // Please change the quiz ID.
return;
}
if ( isset( $quiz_data['results'] ) && is_array( $quiz_data['results'] ) ) {
foreach ( $quiz_data['results'] as $key => $value ) {
$quiz_data['results'][ $key ]['order'] = $key;
$changed = true;
}
}
if ( $changed ) {
$_POST['data'] = json_encode( $quiz_data );
}
},
8
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment