-
Notifications
You must be signed in to change notification settings - Fork 92
gw-advanced-merge-tags.php: Added support for :all_fields modifier to show data for dynamically populated entries.
#1011
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
Changes from all commits
2b6afec
3e6b6fe
35cdede
9ea8e1e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -506,6 +506,35 @@ public function handle_field_modifiers( $value, $input_id, $modifier, $field, $r | |
| return rgar( $value_array, $index ); | ||
| } | ||
| break; | ||
| case 'all_fields': | ||
| // Only to be applied for GPPA scenarios, where we may using dynamically populated entry ID data. | ||
| if ( ! is_callable( 'gp_populate_anything' ) || ! gp_populate_anything()->is_field_dynamically_populated( $field ) ) { | ||
| break; | ||
| } | ||
|
|
||
| // {all_fields} merge tag support needs to get the entry IDs from the raw value. | ||
| $entries = json_decode( $raw_value, true ); | ||
|
|
||
| // loop through each entry ID and get the {all_fields} output. | ||
| $output = ''; | ||
| foreach ( $entries as $entry_id ) { | ||
| $entry = GFAPI::get_entry( $entry_id ); | ||
| $form = GFAPI::get_form( $entry['form_id'] ); | ||
|
|
||
| // Safety check: Ensure the entry belongs to the same form as the field. | ||
| if ( $field->{'gppa-choices-primary-property'} != $entry['form_id'] ) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For added security, I'm curious if you could somehow recreate this logic or extract the logic in GPPA into a method that could be re-used: https://github.com/gravitywiz/gp-populate-anything/blob/a924ffcc780cc4bb01c117a194c1fa674fda6193/class-gp-populate-anything.php#L2608-L2644 Alternatively, if it's only used in the context of admins, you could add a security disclaimer to this modifier saying that it should not be used in places where non-admins can see the output of this merge tag modifier. |
||
| break; | ||
| } | ||
|
|
||
| // Get the {all_fields} output for each entry. | ||
| $all_fields_output = GFCommon::replace_variables( '{all_fields}', $form, $entry, false, false, false ); | ||
|
|
||
| $output .= $all_fields_output . '<br>'; | ||
| } | ||
|
|
||
| // if no entries were found, return the original value. | ||
| $value = $output ? $output : $value; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am open to different names for this like
all_dynamic_entriesor something? Curious what @spivurno thinks.