PluginProbe
weForms – Easy Drag & Drop Contact Form Builder For WordPress / 1.6.14
weForms – Easy Drag & Drop Contact Form Builder For WordPress v1.6.14
1.6.7 1.6.8 1.6.9 1.6.12 1.6.13 1.6.14 1.6.15 1.6.16 1.6.17 1.6.18 1.6.19 1.6.2 1.6.20 1.6.21 1.6.22 1.6.23 1.6.24 1.6.25 1.6.26 1.6.27 1.6.28 1.6.3 1.6.4 1.6.5 1.6.6 All 74 releases
← All changes | includes/class-notification.php +53 -19 1.6.81.6.14 View file →
@@ -462,34 +462,66 @@
462 462 }
463 463 }
464 464
465 465 /**
466 - * Parse out the custom fields with entry meta values
466 + * Parse out the custom fields with options or values. Since the options are what is stored, options may need to be
467 + * used to find the value from the field settings.
467 468 *
468 - * @param string $text
469 + * For example, let's say we have the following options:
470 + * DEPARTMENT / EMAIL
471 + * Support / support@example.com
472 + * Sales / sales@example.com
469 473 *
470 - * @return string
474 + * Users need the ability to pass {field:department} and get "Support",
475 + * and {value:department} to get support@email.com
476 + *
477 + * @param string $text The text to parse.
478 + * @param int $entry_id The entry ID. Optional. Default null if tags to be replaced are on the frontend.
479 + *
480 + * @return string $text The parsed text.
471 481 */
472 - public static function replace_field_tags( $text, $entry_id ) {
473 - $pattern = '/{field:(\w*)}/';
482 + public static function replace_field_tags( $text, $entry_id = null ) {
483 + // Validate data.
484 + if ( empty( $text ) || !isset( $entry_id ) ) {
485 + return;
486 + }
474 487
475 - preg_match_all( $pattern, $text, $matches );
488 + // Users looking for {field:something} or {value:something}, determine which one.
489 + $is_field = preg_match_all( '/{field:(\w*)}/', $text, $matches_field );
490 + $is_value = preg_match_all( '/{value:(\w*)}/', $text, $matches_value );
476 491
477 - // bail out if nothing found to be replaced
478 - if ( !$matches ) {
479 - return $text;
492 + if ( $is_field ) {
493 + $meta_keys = $matches_field[1];
494 + // Create an array of meta values to replace.
495 + $meta_values = array();
496 + foreach ( $meta_keys as $meta_key ) {
497 + $meta_value = weforms_get_entry_meta( $entry_id, $meta_key, true );
498 + // Add values to the array.
499 + array_push( $meta_values, $meta_value );
500 + if ( is_array( $meta_value ) ) {
501 + $meta_value = implode( WeForms::$field_separator, $meta_value );
502 + }
503 + }
504 + // $text may include HTML tags, only replace tag that was matched. Replace all matches.
505 + $text = str_replace( $matches_field[0], $meta_values, $text );
480 506 }
481 -
482 - foreach ( $matches[1] as $index => $meta_key ) {
483 - $meta_value = weforms_get_entry_meta( $entry_id, $meta_key, true );
484 -
485 - if ( is_array( $meta_value ) ) {
486 - $meta_value = implode( WeForms::$field_separator, $meta_value );
507 + if ( $is_value ) {
508 + $meta_keys = $matches_value[1];
509 + // Create an array of modified values to replace.
510 + $modified_values = array();
511 + foreach ( $meta_keys as $meta_key ) {
512 + $form_field_values = WeForms_Form_Entry::get_form( $entry_id )->get_field_values()[ $meta_key ]['options'];
513 + $meta_value = weforms_get_entry_meta( $entry_id, $meta_key, true );
514 + $modified_value = array_search( $meta_value, $form_field_values );
515 + // Add values to the array.
516 + array_push( $modified_values, $modified_value );
517 + if ( is_array( $modified_value ) ) {
518 + $modified_value = implode( WeForms::$field_separator, $modified_value );
519 + }
487 520 }
488 -
489 - $text = str_replace( $matches[0][$index], $meta_value, $text );
521 + // $text may include HTML tags, only replace tag that was matched.
522 + $text = str_replace( $matches_value[0], $modified_values, $text );
490 523 }
491 -
492 524 return $text;
493 525 }
494 526
495 527 /**
@@ -647,9 +679,9 @@
647 679 $table .= '</tr>';
648 680 $table .= '<tr class="field-value">';
649 681 $table .= '<td>';
650 682
651 - if ( in_array( $value['type'], [ 'multiple_select', 'checkbox_field' ] ) ) {
683 + if ( in_array( $value['type'], array( 'multiple_select', 'checkbox_field' ) ) ) {
652 684 $field_value = is_array( $field_value ) ? $field_value : [];
653 685
654 686 if ( $field_value ) {
655 687 $table .= '<ul>';
@@ -660,8 +692,10 @@
660 692 $table .= '</ul>';
661 693 } else {
662 694 $table .= '&mdash;';
663 695 }
696 + } elseif ( in_array( $value['type'], array( 'google_map' ) ) ) {
697 + $table .= $field_value['address'];
664 698 } else {
665 699 $table .= $field_value;
666 700 }
667 701