You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit f37a492
Browse filesBrowse the repository at this point in the historyBrowse files
fix: record settings errors on Gravity Forms field objects
Gravity Forms 2.5+ takes the settings field object by reference in
set_field_error(). Passing an array crashed every refused save with a
fatal error on PHP 8, including the existing custom-metadata checks on
feeds. Errors now go through set_setting_error(), which looks the field
up through the settings renderer and falls back to the field being
validated. The test stubs now follow the same contract.
Found by testing against real Gravity Forms 2.7.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: class-gf-paystack.php
+24-8Lines changed: 24 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -860,17 +860,17 @@ public function validate_custom_meta($field)
860
860
861
861
// If there are more than 20 metadata keys, set field error.
862
862
if ($meta_count > 20) {
863
-
$this->set_field_error(array(esc_html__('You may only have 20 custom keys.'), 'gravityformspaystack'));
863
+
$this->set_setting_error('metaData', esc_html__('You may only have 20 custom keys.', 'gravityformspaystack'), $field);
864
864
return;
865
865
}
866
866
867
867
// Loop through metadata and check the key name length (custom_key).
868
868
foreach ($meta_dataas$meta) {
869
869
if (empty($meta['custom_key']) && !empty($meta['value'])) {
870
-
$this->set_field_error(array('name' => 'metaData'), esc_html__("A field has been mapped to a custom key without a name. Please enter a name for the custom key, remove the metadata item, or return the corresponding drop down to 'Select a Field'.", 'gravityformspaystack'));
870
+
$this->set_setting_error('metaData', esc_html__("A field has been mapped to a custom key without a name. Please enter a name for the custom key, remove the metadata item, or return the corresponding drop down to 'Select a Field'.", 'gravityformspaystack'), $field);
871
871
break;
872
872
} elseif (strlen($meta['custom_key']) > 40) {
873
-
$this->set_field_error(array('name' => 'metaData'), sprintf(esc_html__('The name of custom key %s is too long. Please shorten this to 40 characters or less.', 'gravityformspaystack'), $meta['custom_key']));
873
+
$this->set_setting_error('metaData', sprintf(esc_html__('The name of custom key %s is too long. Please shorten this to 40 characters or less.', 'gravityformspaystack'), esc_html($meta['custom_key'])), $field);
874
874
break;
875
875
}
876
876
}
@@ -2107,15 +2107,15 @@ public function validate_credentials($field = null)
$this->set_field_error(array('name' => 'api_mode'), sprintf(esc_html__('Your %1$s settings have a problem. Select %2$s to see it. No settings were saved.', 'gravityformspaystack'), $mode, $mode === 'test' ? esc_html__('Test', 'gravityformspaystack') : esc_html__('Live', 'gravityformspaystack')));
2118
+
$this->set_setting_error('api_mode', sprintf(esc_html__('Your %1$s settings have a problem. Select %2$s to see it. No settings were saved.', 'gravityformspaystack'), $mode, $mode === 'test' ? esc_html__('Test', 'gravityformspaystack') : esc_html__('Live', 'gravityformspaystack')));
2119
2119
}
2120
2120
}
2121
2121
}
@@ -2247,7 +2247,7 @@ public function validate_subscription_plans($field, $value = null)
gf_paystack_test_check(!preg_match('/set_field_error\(\s*array\(/', $plugin_src), 'no field error is raised with an array (Gravity Forms 2.5+ needs the field object)');
438
+
439
+
$meta_run = function ($meta, $renderer_fields = null) {
gf_paystack_test_check(($a->field_errors['metaData'] ?? '') === 'You may only have 20 custom keys.', 'feed metadata over 20 keys is flagged on metaData');
gf_paystack_test_check(strpos($a->field_errors['metaData'] ?? '', 'A field has been mapped to a custom key without a name.') === 0, 'feed metadata without a key name is flagged');
gf_paystack_test_check(strpos($a->field_errors['metaData'] ?? '', '<b>') !== false && strpos($a->field_errors['metaData'], '<b>') === false, 'feed metadata long key name is flagged and escaped');
0 commit comments