From 2c1ba68a1366827b4a39dac3a458e648828f8329 Mon Sep 17 00:00:00 2001 From: Saif Sultan Date: Mon, 24 Mar 2025 12:02:39 +0530 Subject: [PATCH 1/2] `gppa-populate-child-entries.php`: Fixed an issue with missing cookie values. --- .../gppa-populate-child-entries.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/gp-populate-anything/gppa-populate-child-entries.php b/gp-populate-anything/gppa-populate-child-entries.php index f4470f962..31cbec468 100644 --- a/gp-populate-anything/gppa-populate-child-entries.php +++ b/gp-populate-anything/gppa-populate-child-entries.php @@ -66,7 +66,20 @@ public function populate_parent_entry_id( $value, $field ) { } else { $session = new GPNF_Session( $field->formId ); $cookie = $session->get_cookie(); - $value = rgar( $cookie, 'hash', '' ); + + // try to find cookie, if available. + if ( ! $cookie ) { + $cookie_name = 'gpnf_form_session_'; + $pattern = '/^' . preg_quote( $cookie_name, '/' ) . '[\w\W]*/'; + $matches = preg_grep($pattern, array_keys($_COOKIE)); + if ( ! empty( $matches ) ) { + foreach ( $matches as $matched_cookie ) { + $cookie = json_decode(stripslashes( $_COOKIE[ $matched_cookie ] ), true); + } + } + } + + $value = rgar( $cookie, 'hash', '' ); } return $value; From 710c14f9f0e3972e6bd17c6531e7ea02294a4959 Mon Sep 17 00:00:00 2001 From: Saif Sultan Date: Tue, 25 Mar 2025 12:07:49 +0530 Subject: [PATCH 2/2] `gppa-populate-child-entries.php`: Fixed an issue with missing cookie values. --- gp-populate-anything/gppa-populate-child-entries.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gp-populate-anything/gppa-populate-child-entries.php b/gp-populate-anything/gppa-populate-child-entries.php index 31cbec468..d96c65563 100644 --- a/gp-populate-anything/gppa-populate-child-entries.php +++ b/gp-populate-anything/gppa-populate-child-entries.php @@ -70,8 +70,8 @@ public function populate_parent_entry_id( $value, $field ) { // try to find cookie, if available. if ( ! $cookie ) { $cookie_name = 'gpnf_form_session_'; - $pattern = '/^' . preg_quote( $cookie_name, '/' ) . '[\w\W]*/'; - $matches = preg_grep($pattern, array_keys($_COOKIE)); + $pattern = '/^' . preg_quote( $cookie_name, '/' ) . '[\w\W]*/'; + $matches = preg_grep( $pattern, array_keys( $_COOKIE ) ); if ( ! empty( $matches ) ) { foreach ( $matches as $matched_cookie ) { $cookie = json_decode(stripslashes( $_COOKIE[ $matched_cookie ] ), true);