|
67 | 67 |
|
68 | 68 | if ( $rows ) { |
69 | 69 | foreach ( $rows as $row ) { |
70 | | - $label = isset( $map['label'] ) ? |
71 | | - apply_filters( 'gppa_acfrm_label', rgar( $row, $map['label'] ), $row, $map['label'] ) : |
72 | | - str_replace( 'gf_custom:', '', $custom_map['label'] ); |
| 70 | + $choice['text'] = isset( $map['label'] ) ? |
| 71 | + apply_filters( 'gppa_acfrm_label', rgar( $row, $map['label'] ), $row, $map['label'] ) : |
| 72 | + ( isset( $custom_map['label'] ) ? str_replace( 'gf_custom:', '', $custom_map['label'] ) : '' ); |
73 | 73 |
|
74 | | - $value = isset( $map['value'] ) ? |
75 | | - apply_filters( 'gppa_acfrm_value', rgar( $row, $map['value'] ), $row, $map['value'] ) : |
76 | | - str_replace( 'gf_custom:', '', $custom_map['value'] ); |
| 74 | + $choice['value'] = isset( $map['value'] ) ? |
| 75 | + apply_filters( 'gppa_acfrm_value', rgar( $row, $map['value'] ), $row, $map['value'] ) : |
| 76 | + ( isset( $custom_map['value'] ) ? str_replace( 'gf_custom:', '', $custom_map['value'] ) : '' ); |
77 | 77 |
|
78 | | - $choice = array( |
79 | | - 'value' => $value, |
80 | | - 'text' => $label, |
81 | | - ); |
| 78 | + $image = isset( $map['image'] ) ? |
| 79 | + apply_filters( 'gppa_acfrm_image', rgar( $row, $map['image'] ), $row, $map['image'] ) : |
| 80 | + ( isset( $custom_map['image'] ) ? str_replace( 'gf_custom:', '', $custom_map['image'] ) : '' ); |
| 81 | + |
| 82 | + if ( $image ) { |
| 83 | + // Get the attachment id from the image url as `Image Choice` field requires `attachment_id` to display Image. |
| 84 | + $attachment_id = attachment_url_to_postid( $image ); |
| 85 | + |
| 86 | + $choice['attachment_id'] = $attachment_id; |
| 87 | + } |
82 | 88 |
|
83 | 89 | if ( isset( $map['inventory_limit'] ) ) { |
84 | 90 | $choice['inventory_limit'] = apply_filters( 'gppa_acfrm_inventory_limit', rgar( $row, $map['inventory_limit'] ), $row, $map['inventory_limit'] ); |
85 | 91 | } |
86 | 92 |
|
87 | 93 | $choice['price'] = isset( $map['price'] ) ? |
88 | | - apply_filters( 'gppa_acfrm_price', rgar( $row, $map['price'] ), $row, $map['price'] ) : |
89 | | - str_replace( 'gf_custom:', '', $custom_map['price'] ); |
| 94 | + apply_filters( 'gppa_acfrm_price', rgar( $row, $map['price'] ), $row, $map['price'] ) : |
| 95 | + ( isset( $custom_map['price'] ) ? str_replace( 'gf_custom:', '', $custom_map['price'] ) : '' ); |
90 | 96 |
|
91 | 97 | $choices[] = $choice; |
92 | 98 | } |
|
0 commit comments