Popup-Maker
Popup-Maker copied to clipboard
Add support for Gravity Forms redirect methods
https://pastebin.com/WY5zXS1g
We tested this code multiple times and looks like it works like a charm and can be used in official repository. I would be thankful for adding annotation that bug was fixed by "Tomasz from OsomStudio.com".
@danieliser I looked at the code submitted in the PasteBin link above just to see what they were suggesting. There are a couple of things that stood out for me. Seems that they ought to be addressed before accepting the code into your codebase.
-
In
public function set_popup_maker_cookie( $entry, $form )
, I can't see any use of the first parameter in the function. What's it used for? -
On line 44, why not do a conditional check for $confirmation_type and $pum_popup_id? If either return falsey (null, empty string), just return early. Include a string that includes an error message so the developer can know why the error occurred. This avoids the 2 nested
if
statements currently wrapped inside the conditional on Line 44. -
By refactoring line 44, if the conditions are true and the code does run, then remove the
if
statement on Line 45. Just get the postmeta and pass it to the variable to run the code between lines 47 - 51 (without the thirdif
statement). -
Complete the docblock for
public function set_popup_maker_cookie( $entry, $form )
to follow WP coding standards.
It was meant to show proof of concept. It will of course becrewritten to match our internal structure. See the support ticket that is related
@danieliser Looking into this a bit. Since there are two ways to submit a GF form (PHP or AJAX) and we have different handlers for each, we will need slightly different solutions for each.
For the PHP, GF submits the form as normal, which does get to our handler. Our handler does increase conversion counts and prepares cookies correctly. However, the PHP handler sends the needed cookie data to the frontend through pum_vars. However, GF then redirects after we process so it creates a new page load that no longer has the cookie data in pum_vars.
For the AJAX, their jQuery(document).trigger('gform_confirmation_loaded', [{$form_id}])
is only called when there is no redirect. Thus, our AJAX handler is never fired at all. Unfortunately, there are no events triggered in the redirect part of their conditional as shown.
else {
jQuery('#gform_{$form_id}').append(contents);
if(window['gformRedirect']) {gformRedirect();}
}
So, in both cases, there doesn't seem to be a straightforward place for us to "hook" into. We will have to do a more "hacky" solution. I'll review their code some more and see if I can find some solutions.
@fpcorso So we'd need to basically pass an extra flag letting our code not to run again.
@danieliser Not sure what you mean. In both PHP and AJAX, the process is broken and no cookies are being set during either submission but for different reasons, as outlined above.
@fpcorso Just re-read from the top this time, missed the context that this is only if they enable the redirect. Everything works fine now with both methods if they don't have the redirect correct? Threw me for a second when you said no cookies were being set, was wondering why we haven't been flooded with tickets for that.
Shame the original code is now gone.
Ok so my first thought is we need to filter the redirect url and add some parameters to it that we can use on the next page to set cookies properly.
Alternatively, and this is something we've never really tried, we could set the cookies in PHP via the action we are already handling.