Skip to content

gppa-populate-child-entries.php: Fixed an issue with missing cookie values. #1055

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion gp-populate-anything/gppa-populate-child-entries.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Comment on lines 68 to +71
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So a cookie exists and but it's not retrieved by the session? Could you explain more about this scenario and why the cookie is not being found?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The standard cookie gpnf_form_session wasn't there, which I thought was to do with some logic on the snippet. But there was another one with the a suffix of gfpreview and form Id (forgot the exact format) available. The proposal here is to look out for that if the standard isn't available.

Copy link
Contributor

@spivurno spivurno Mar 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we'll want to identify why the expected cookie isn't there and why the unexpected cookie is there.

$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;
Expand Down
Loading