-
Notifications
You must be signed in to change notification settings - Fork 91
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
gppa-populate-child-entries.php
: Fixed an issue with missing cookie values.
#1055
base: master
Are you sure you want to change the base?
Conversation
WalkthroughThe changes update the cookie handling within the Changes
Sequence Diagram(s)sequenceDiagram
participant Caller as Caller
participant Method as populate_parent_entry_id
participant CookieStorage as $_COOKIE
Caller ->> Method: Call populate_parent_entry_id
Method ->> Method: Attempt to retrieve cookie using get_cookie()
alt Cookie exists
Method ->> Caller: Return cookie['hash'] value
else Cookie missing
Method ->> CookieStorage: Scan for keys matching "gpnf_form_session_"
CookieStorage -->> Method: Return matching keys
Method ->> Method: Iterate through matches and decode JSON data
Method ->> Caller: Return extracted cookie['hash'] value
end
Suggested reviewers
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
gp-populate-anything/gppa-populate-child-entries.php (1)
69-82
: Good enhancement to the cookie retrieval logic.The additional code now properly handles the case when the cookie is not available through the primary retrieval method, addressing the issue mentioned in the PR objectives where the temporary parent entry ID fails to populate after form submission and reopening.
A few suggestions to make this more robust:
Since you're processing multiple cookies but only keeping the last one in the loop, consider adding a
break
statement once you've found a valid cookie to avoid unnecessary iterations.Add validation after JSON decoding to ensure the cookie has the expected structure before using it.
if ( ! empty( $matches ) ) { foreach ( $matches as $matched_cookie ) { $cookie = json_decode(stripslashes( $_COOKIE[ $matched_cookie ] ), true); + if ( $cookie && isset( $cookie['hash'] ) ) { + break; // Valid cookie found, no need to process more + } } }
$cookie = $session->get_cookie(); | ||
$value = rgar( $cookie, 'hash', '' ); | ||
|
||
// try to find cookie, if available. | ||
if ( ! $cookie ) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Context
⛑️ Ticket(s): https://secure.helpscout.net/conversation/2882383665/79731
Summary
The temporary parent entry ID doesn't populate the field on the form after the form is submitted and opened again. The cookie wasn't found strangely. Added logic to look out for the cookie in this context.