xwp / stream

🗄️ Stream plugin for WordPress
https://wordpress.org/plugins/stream/
GNU General Public License v2.0
405 stars 119 forks source link

PHP Warnings/Notices on Gravity Forms note added #1446

Closed zach-adams closed 9 months ago

zach-adams commented 9 months ago

Bug Report

Expected Behavior

Upon using the "Save Progress" form feature in Gravity Forms along with an email Add-On provider there should be no warnings/issues thrown.

Actual Behavior

A warning/notice is thrown because the email Add-On provider tries to create an entry note on a partial entry (which have no proper "entry_id" as they're saved in a separate "gf_draft_submissions" table), so the note-related actions/filters are still run by the email Add-On but provide said hooks with "null" instead of a proper "entry/lead id", and since there's no check in the Stream connector class for if the entry/lead id is a valid int it leads to the "$lead" on line 675 being set to "false" and then treated subsequently as an array:

[12-Sep-2023 23:58:38 UTC] PHP Warning:  Trying to access array offset on value of type bool in /../public_html/wp-content/plugins/stream/connectors/class-connector-gravityforms.php on line 676
[12-Sep-2023 23:58:38 UTC] PHP Warning:  Trying to access array offset on value of type null in /../public_html/wp-content/plugins/stream/connectors/class-connector-gravityforms.php on line 684
[12-Sep-2023 23:58:38 UTC] PHP Warning:  Trying to access array offset on value of type null in /../public_html/wp-content/plugins/stream/connectors/class-connector-gravityforms.php on line 685

File/location of issue:

https://github.com/xwp/stream/blob/4fb568dcc82bd8a7102e74c2a60fa5cd9493216c/connectors/class-connector-gravityforms.php#L657-L691

The fix should be as simple as checking if "$lead_id" in the above method is empty and returning early if that's the case. A further check on the whether the "$lead" variable is a valid array will also be needed as "\GFFormsModel::get_lead" can return a boolean if no entry is found for whatever reason.

I'll open a PR regarding this issue shortly

Steps to Reproduce the Problem

  1. Set PHP error_reporting to include notices & warnings
  2. Install Gravity Forms, SendGrid Add-On, and Partial Entries Add-On
  3. Setup small test form, in the Form Settings enable "Enable Save and Continue", and enable the "Partial Entries" feature for it as well
  4. Set the "Save & continue notification email" to use the Add-On email providers instead of the built-in "WordPress" one
  5. Visit form and attempt to use the "Save Progress" feature
  6. Check confirmation message or PHP debug log for above Warnings or Notices

Screenshots

Just a quick thing to point out is that when using the default "WordPress" email provider service for this Save & continue notification email it works as it should & no warning/notice is thrown, and that's because GF calls this internal method which explicitly checks for whether the "$entry_id" is empty or not before it tries to create a note, and most email Add-On providers seem to skip this check before trying to create a note.

In GF file "forms_model.php":

2023-09-13_10-10-l9tSRe1g

System Information