Skip to content

Commit 2c1ba68

Browse files
committed
gppa-populate-child-entries.php: Fixed an issue with missing cookie values.
1 parent ff20239 commit 2c1ba68

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

gp-populate-anything/gppa-populate-child-entries.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,20 @@ public function populate_parent_entry_id( $value, $field ) {
6666
} else {
6767
$session = new GPNF_Session( $field->formId );
6868
$cookie = $session->get_cookie();
69-
$value = rgar( $cookie, 'hash', '' );
69+
70+
// try to find cookie, if available.
71+
if ( ! $cookie ) {
72+
$cookie_name = 'gpnf_form_session_';
73+
$pattern = '/^' . preg_quote( $cookie_name, '/' ) . '[\w\W]*/';
74+
$matches = preg_grep($pattern, array_keys($_COOKIE));
75+
if ( ! empty( $matches ) ) {
76+
foreach ( $matches as $matched_cookie ) {
77+
$cookie = json_decode(stripslashes( $_COOKIE[ $matched_cookie ] ), true);
78+
}
79+
}
80+
}
81+
82+
$value = rgar( $cookie, 'hash', '' );
7083
}
7184

7285
return $value;

0 commit comments

Comments
 (0)