Skip to content

Commit 7eb6216

Browse files
authored
gppa-acf-repeater-mapper.php: Added Image Choice field support in GPPA acf repeater mapper.
1 parent 0390f25 commit 7eb6216

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

gp-populate-anything/gppa-acf-repeater-mapper.php

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,26 +67,34 @@
6767

6868
if ( $rows ) {
6969
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'] ) : '' );
7373

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'] ) : '' );
7777

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+
if ( $attachment_id ) {
87+
$choice['attachment_id'] = $attachment_id;
88+
}
89+
}
8290

8391
if ( isset( $map['inventory_limit'] ) ) {
8492
$choice['inventory_limit'] = apply_filters( 'gppa_acfrm_inventory_limit', rgar( $row, $map['inventory_limit'] ), $row, $map['inventory_limit'] );
8593
}
8694

8795
$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'] );
96+
apply_filters( 'gppa_acfrm_price', rgar( $row, $map['price'] ), $row, $map['price'] ) :
97+
( isset( $custom_map['price'] ) ? str_replace( 'gf_custom:', '', $custom_map['price'] ) : '' );
9098

9199
$choices[] = $choice;
92100
}

0 commit comments

Comments
 (0)