Skip to content

Commit fe1c843

Browse files
committed
gppa-acf-repeater-mapper.php: Add support for custom values with ACF field property template.
1 parent 3559587 commit fe1c843

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

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

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
* 2. Select the "Post, User or Term" object type.
1212
* 3. Apply any desired filters to determine which post(s) should have their repeater data populated.
1313
* 4. Use the "Choice Template" to match each choice property to a repeater subfield.
14-
* For example, if your repeater is labeled "parts" and you want to populate the "name" subfield as the choice label,
15-
* select "parts_0_name" for the "Label" template. [Screenshot](https://gwiz.io/3m4Yq0y).
14+
* For example, if your repeater is labeled "parts" and you want to populate the "name" subfield as the choice label,
15+
* select "parts_0_name" for the "Label" template. [Screenshot](https://gwiz.io/3m4Yq0y).
1616
* 5. Add the "gppa-acf-repeater-mapper" to the field's CSS Class Name setting.
1717
*
1818
* Video
@@ -22,8 +22,8 @@
2222
* Plugin Name: GP Populate Anything — ACF Repeater Mapper
2323
* Plugin URI: https://gravitywiz.com/documentation/gravity-forms-populate-anything/
2424
* Description: Populate all rows from an ACF Repeater into a choice-based field.
25-
* Author: Gravity Wiz
26-
* Version: 0.3
25+
* Author: Gravity Wiz
26+
* Version: 0.4
2727
* Author URI: https://gravitywiz.com
2828
*/
2929
add_filter( 'gppa_input_choices', function( $choices, $field, $objects ) {
@@ -32,7 +32,8 @@
3232
return $choices;
3333
}
3434

35-
$map = array();
35+
$map = array();
36+
$custom_map = array();
3637

3738
foreach ( $field->{'gppa-choices-templates'} as $template => $key ) {
3839
/**
@@ -43,7 +44,9 @@
4344
*/
4445
if ( preg_match( '/meta_([^0-9]+)_([0-9]+)_(.+)/', $key, $matches ) ) {
4546
list( , $repeater, $index, $subfield ) = $matches;
46-
$map[ $template ] = $subfield;
47+
$map[ $template ] = $subfield;
48+
} else {
49+
$custom_map[ $template ] = $key;
4750
}
4851
}
4952

@@ -64,20 +67,31 @@
6467

6568
if ( $rows ) {
6669
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'] );
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'] );
77+
6778
$choice = array(
68-
'value' => apply_filters( 'gppa_acfrm_value', rgar( $row, $map['value'] ), $row, $map['value'] ),
69-
'text' => apply_filters( 'gppa_acfrm_label', rgar( $row, $map['label'] ), $row, $map['label'] ),
79+
'value' => $value,
80+
'text' => $label,
7081
);
82+
7183
if ( isset( $map['inventory_limit'] ) ) {
7284
$choice['inventory_limit'] = apply_filters( 'gppa_acfrm_inventory_limit', rgar( $row, $map['inventory_limit'] ), $row, $map['inventory_limit'] );
7385
}
74-
if ( isset( $map['price'] ) ) {
75-
$choice['price'] = apply_filters( 'gppa_acfrm_price', rgar( $row, $map['price'] ), $row, $map['price'] );
76-
}
86+
87+
$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'] );
90+
7791
$choices[] = $choice;
7892
}
7993
}
8094
}
8195

8296
return $choices;
83-
}, 10, 3 );
97+
}, 10, 3 );

0 commit comments

Comments
 (0)