From e5a1b043785a199feaf53910188f83a60423b19a Mon Sep 17 00:00:00 2001 From: randhirexpresstech Date: Mon, 1 Jul 2024 09:54:09 +0530 Subject: [PATCH] adjust add result function for import feature --- php/classes/class-qmn-quiz-manager.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/php/classes/class-qmn-quiz-manager.php b/php/classes/class-qmn-quiz-manager.php index 97817780d..25f4c85bc 100644 --- a/php/classes/class-qmn-quiz-manager.php +++ b/php/classes/class-qmn-quiz-manager.php @@ -1870,7 +1870,7 @@ public function qsm_get_quiz_to_reload() { * * @return boolean results added or not */ - private function add_quiz_results( $data ) { + public function add_quiz_results( $data ) { global $wpdb; if ( empty( $wpdb ) || empty( $data['qmn_array_for_variables'] ) || empty( $data['results_array'] ) || empty( $data['unique_id'] ) || ! isset( $data['http_referer'] ) || ! isset( $data['form_type'] ) ) { return false; @@ -1883,6 +1883,9 @@ private function add_quiz_results( $data ) { $wpdb->suppress_errors(); try { + if ( empty( $data['page_name'] ) ) { + $data['page_name'] = url_to_postid( $data['http_referer'] ) ? get_the_title( url_to_postid( $data['http_referer'] ) ) : ''; + } $res = $wpdb->insert( $table_name, array( @@ -1902,11 +1905,11 @@ private function add_quiz_results( $data ) { 'time_taken' => $data['qmn_array_for_variables']['time_taken'], 'time_taken_real' => gmdate( 'Y-m-d H:i:s', strtotime( $data['qmn_array_for_variables']['time_taken'] ) ), 'quiz_results' => maybe_serialize( $data['results_array'] ), - 'deleted' => 0, + 'deleted' => ( isset( $data['deleted'] ) && 1 === intval( $data['deleted'] ) ) ? 1 : 0, 'unique_id' => $data['unique_id'], 'form_type' => $data['form_type'], 'page_url' => $data['http_referer'], - 'page_name' => url_to_postid( $data['http_referer'] ) ? get_the_title( url_to_postid( $data['http_referer'] ) ) : '', + 'page_name' => sanitize_text_field( $data['page_name'] ), ), array( '%d',