Skip to content

Commit 9635651

Browse files
gppa-force-dyn-pop-on-gv-edit.php: Updated snippet to work with GPPA 2.0+.
1 parent b9fca3b commit 9635651

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

gp-populate-anything/gppa-force-dyn-pop-on-gv-edit.php

+17-7
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,23 @@
66
* If you need to force repopulation when editing a child entry via GravityView, see:
77
* https://github.com/gravitywiz/snippet-library/blob/master/gp-populate-anything/gppa-gpnf-force-dyn-pop-on-gv-edit.php
88
*/
9-
add_filter( 'gravityview/edit_entry/field_value', function( $field_value, $field ) {
10-
// Update "123" to your form ID and "4" to your field ID.
11-
if ( $field->formId == 123 && $field->id == 4 ) {
12-
if ( isset( $GLOBALS['gppa-field-values'] ) ) {
13-
$hydrated_field = gp_populate_anything()->hydrate_field( $field, GFAPI::get_form( $field->formId ), array(), null, false );
14-
$field_value = $hydrated_field['field_value'];
9+
add_filter( 'gravityview/edit_entry/field_value', function( $field_value, $field, $_this ) {
10+
// Start customizing
11+
$form_id = 1;
12+
$field_ids_to_populate = array( 9, 10 );
13+
// End customizing
14+
15+
if ( $field->formId == $form_id && in_array( $field->id, $field_ids_to_populate ) ) {
16+
$populated_field = gp_populate_anything()->populate_field( $field, $_this->form, gp_populate_anything()->get_posted_field_values( $_this->form ), $_this->entry );
17+
18+
if ( $field->storageType === 'json' ) {
19+
$field_value = json_encode( $populated_field['field_value'] );
20+
} else {
21+
$field_value = $populated_field['field_value'];
1522
}
23+
24+
$GLOBALS['gppa-field-values'][ $field->formId ][ $field->id ] = $field_value;
1625
}
26+
1727
return $field_value;
18-
}, 10, 2 );
28+
}, 10, 3 );

0 commit comments

Comments
 (0)