Skip to content

Commit 2b6ac85

Browse files
committed
gpeb-add-new-entry.php: Fixed issue where "is_new" parameter was saved to field generating false positives on subsequent edits.
1 parent f523e97 commit 2b6ac85

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

gp-entry-blocks/gpeb-add-new-entry.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,11 @@ public function init() {
4242
}
4343

4444
add_filter( 'wp', array( gw_manual_entries(), 'process_query_string' ) );
45-
4645
add_filter( 'gfme_is_add_entry_request', array( $this, 'is_add_entry_request' ) );
47-
4846
add_filter( 'gfme_edit_url', array( $this, 'set_edit_url' ), 10, 3 );
49-
5047
add_filter( 'gpeb_edit_form_entry', array( $this, 'populate_is_new_parameter' ) );
51-
5248
add_filter( 'gpeb_cleaned_current_url', array( $this, 'remove_is_new_parameter' ) );
49+
add_filter( 'gform_pre_submission', array( $this, 'remove_is_new_field_value_on_submission' ) );
5350

5451
}
5552

@@ -80,6 +77,20 @@ public function populate_is_new_parameter( $entry ) {
8077
return $entry;
8178
}
8279

80+
/**
81+
* Prevent the is_new field value from being saved to the entry so that on subsequent page loads, conditional logic
82+
* based on the "is_new" field will not generate a false positive.
83+
*
84+
* @param $form
85+
*/
86+
public function remove_is_new_field_value_on_submission( $form ) {
87+
foreach ( $form['fields'] as $field ) {
88+
if ( $field->inputName === 'is_new' ) {
89+
$_POST[ "input_{$field->id}" ] = '';
90+
}
91+
}
92+
}
93+
8394
public function remove_is_new_parameter( $url ) {
8495
return remove_query_arg( 'is_new', $url );
8596
}

0 commit comments

Comments
 (0)