Skip to content
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

PHP Warnings/Notices on Gravity Forms note added #1446

Closed
zach-adams opened this issue Sep 13, 2023 · 0 comments · Fixed by #1447
Closed

PHP Warnings/Notices on Gravity Forms note added #1446

zach-adams opened this issue Sep 13, 2023 · 0 comments · Fixed by #1447

Comments

@zach-adams
Copy link
Contributor

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:

/**
* Logs note creation on lead.
*
* @action gform_post_note_added
*
* @param int $note_id Note ID.
* @param int $lead_id Lead ID.
* @param int $user_id User ID of note author.
* @param string $user_name Username of note author.
* @param string $note Note object.
* @param string $note_type Note type.
*/
public function callback_gform_post_note_added( $note_id, $lead_id, $user_id, $user_name, $note, $note_type ) {
unset( $user_id );
unset( $user_name );
unset( $note );
unset( $note_type );
$lead = \GFFormsModel::get_lead( $lead_id );
$form = $this->get_form( $lead['form_id'] );
$this->log(
/* translators: %1$d: an ID, %2$d: another ID, %3$s: a form title (e.g. "42", "7", "Contact Form") */
__( 'Note #%1$d added to lead #%2$d on "%3$s" form', 'stream' ),
array(
'note_id' => $note_id,
'lead_id' => $lead_id,
'form_title' => $form['title'],
'form_id' => $form['id'],
),
$note_id,
'notes',
'added'
);
}

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

  • Stream plugin version: 3.9.3
  • WordPress version: 6.3.1
  • PHP version: 8.1.23
  • Browser: Google Chrome | 117.0.5938.62
  • Computer operating system: macOS Version 13.5.2 (Build 22G91)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant