Skip to content

Instantly share code, notes, and snippets.

@patrickfreitasdev
Created August 22, 2020 23:49
Show Gist options
  • Select an option

  • Save patrickfreitasdev/4263cfd629aaf34f0b066f494ac0db8c to your computer and use it in GitHub Desktop.

Select an option

Save patrickfreitasdev/4263cfd629aaf34f0b066f494ac0db8c to your computer and use it in GitHub Desktop.
<?php
add_action( 'forminator_quizzes_submit_before_set_fields', function($entry){
$entry->set_fields(
array(
array(
'name' => '_forminator_user_ip',
'value' => Forminator_Geo::get_user_ip(),
)
)
);
});
add_action( 'forminator_before_submit_quizzes', function( $form_model ) {
$form_id = $form_model->id;
$form_ids = array( 536, 74, 20 ); // IDs of the Quizes for disabling submission
if ( in_array( intval( $form_id ), $form_ids, true ) ) {
$user_ip = Forminator_Geo::get_user_ip();
if ( ! empty( $user_ip ) ) {
$last_entry = Forminator_Form_Entry_Model::get_last_entry_by_ip_and_form( $form_id, $user_ip );
if ( ! empty( $last_entry ) ) {
$entry = Forminator_API::get_entry( $form_id, $last_entry );
$current_time = strtotime( date( 'Y-m-d H:i:s' ) );
$future_time = strtotime( '+1 day', strtotime( $entry->date_created_sql ) );
if ( $current_time < $future_time ) {
wp_send_json_success(
array(
'result' => 'You cannot submit this quiz within 24 hours after submitting once!',
'result_url' => '',
'type' => 'nowrong',
)
);
}
}
}
}
},
15
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment