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

gw-advanced-merge-tags.php: Fixed an issue with unknown advanced merge tag label. #860

Merged
merged 1 commit into from
Jul 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 40 additions & 39 deletions gravity-forms/gw-advanced-merge-tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,61 +160,62 @@ public function replace_merge_tags( $text, $form, $entry ) {
// matches {Label:#fieldId#}
// {Label:#fieldId#:#options#}
// {Custom:#options#}
while ( preg_match_all( '/{(\w+)(:([\w&,=)(\-]+)){1,2}}/mi', $text, $matches, PREG_SET_ORDER ) ) {
preg_match_all( '/{(\w+)(:([\w&,=)(\-]+)){1,2}}/mi', $text, $matches, PREG_SET_ORDER );

foreach ( $matches as $match ) {
foreach ( $matches as $match ) {

list( $tag, $type, $args_match, $args_str ) = array_pad( $match, 4, false );
parse_str( $args_str, $args );
list( $tag, $type, $args_match, $args_str ) = array_pad( $match, 4, false );
parse_str( $args_str, $args );

$args = array_map( array( $this, 'check_for_value_modifiers' ), $args );
$value = '';
$args = array_map( array( $this, 'check_for_value_modifiers' ), $args );
$value = '';

switch ( $type ) {
case 'post':
$value = $this->get_post_merge_tag_value( $args );
break;
case 'post_meta':
case 'custom_field':
$value = $this->get_post_meta_merge_tag_value( $args );
break;
case 'source_post':
if ( empty( $entry ) || ! rgar( $entry, 'id' ) ) {
break;
}
$source_post_id = gform_get_meta( $entry['id'], 'source_post_id' );
if ( ! $source_post_id ) {
break;
}
$args['id'] = $source_post_id;
$args['prop'] = $args_str;
$value = $this->get_post_merge_tag_value( $args );
break;
case 'entry':
$args['entry'] = $entry;
$value = $this->get_entry_merge_tag_value( $args );
switch ( $type ) {
case 'post':
$value = $this->get_post_merge_tag_value( $args );
break;
case 'post_meta':
case 'custom_field':
$value = $this->get_post_meta_merge_tag_value( $args );
break;
case 'source_post':
if ( empty( $entry ) || ! rgar( $entry, 'id' ) ) {
break;
case 'entry_meta':
$args['entry'] = $entry;
$value = $this->get_entry_meta_merge_tag_value( $args );
}
$source_post_id = gform_get_meta( $entry['id'], 'source_post_id' );
if ( ! $source_post_id ) {
break;
}
$args['id'] = $source_post_id;
$args['prop'] = $args_str;
$value = $this->get_post_merge_tag_value( $args );
break;
case 'entry':
$args['entry'] = $entry;
$value = $this->get_entry_merge_tag_value( $args );
break;
case 'entry_meta':
$args['entry'] = $entry;
$value = $this->get_entry_meta_merge_tag_value( $args );
break;
// @todo: Add a whitelist here that the user can provide when they initialize the class.
// case 'callback':
// $args['callback'] = array_shift( array_keys( $args ) );
// unset( $args[ $args['callback'] ] );
// $args['entry'] = $entry;
// $value = $this->get_callback_merge_tag_value( $args );
// break;
}
default:
continue 2;
}

// @todo: figure out if/how to support values that are not strings
if ( is_array( $value ) || is_object( $value ) ) {
$value = '';
}
// @todo: figure out if/how to support values that are not strings
if ( is_array( $value ) || is_object( $value ) ) {
$value = '';
}

$text = str_replace( $tag, $value, $text );
$text = str_replace( $tag, $value, $text );

}
}

return $text;
Expand Down
Loading