From 0193cdbfeab00058467858ae2b5f9015aee68831 Mon Sep 17 00:00:00 2001 From: etchirag Date: Tue, 26 Nov 2024 09:49:28 +0530 Subject: [PATCH] Fixed issue with undefined array key warning --- php/classes/class-qmn-plugin-helper.php | 2 +- php/template-variables.php | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/php/classes/class-qmn-plugin-helper.php b/php/classes/class-qmn-plugin-helper.php index 7b5a5927..9440fa56 100644 --- a/php/classes/class-qmn-plugin-helper.php +++ b/php/classes/class-qmn-plugin-helper.php @@ -1097,7 +1097,7 @@ public function convert_contacts_to_preferred_date_format( $qsm_qna_array ) { $qsm_contact_array = $qsm_qna_array['contact']; foreach ( $qsm_contact_array as $qsm_contact_id => $qsm_contact ) { - if ( 'date' === $qsm_contact['type'] && '' !== $qsm_contact['value'] && null !== $GLOBALS['qsm_date_format'] ) { + if ( ( isset($qsm_contact['type']) && 'date' === $qsm_contact['type'] ) && ( isset($qsm_contact['value']) && '' !== $qsm_contact['value'] ) && null !== $GLOBALS['qsm_date_format'] ) { $qsm_qna_array['contact'][ $qsm_contact_id ]['value'] = date_i18n( $GLOBALS['qsm_date_format'], strtotime( ( $qsm_contact['value'] ) ) ); } } diff --git a/php/template-variables.php b/php/template-variables.php index a67d9baa..5abac46b 100644 --- a/php/template-variables.php +++ b/php/template-variables.php @@ -514,12 +514,14 @@ function qsm_all_contact_fields_variable( $content, $results ) { $return = ''; if ( isset( $results['contact'] ) && ( is_array( $results['contact'] ) || is_object( $results['contact'] ) ) ) { foreach ( $results['contact'] as $results_contact ) { - $options = qsm_get_options_of_contact_fields($contact_form, $results_contact['label'], $results_contact['type'] ); - $isRadioOrSelect = in_array($results_contact['type'], [ 'radio', 'select' ], true); - $hasOptions = ! empty(trim($options)); + if ( isset( $results_contact['label'] ) && isset( $results_contact['type'] ) && isset( $results_contact['value'] ) ) { + $options = qsm_get_options_of_contact_fields($contact_form, $results_contact['label'], $results_contact['type'] ); + $isRadioOrSelect = in_array($results_contact['type'], [ 'radio', 'select' ], true); + $hasOptions = ! empty(trim($options)); - if ( ($isRadioOrSelect && $hasOptions) || ! $isRadioOrSelect ) { - $return .= $results_contact['label'] . ': ' . $results_contact['value'] . '
'; + if ( ($isRadioOrSelect && $hasOptions) || ! $isRadioOrSelect ) { + $return .= $results_contact['label'] . ': ' . $results_contact['value'] . '
'; + } } } }