Skip to content

Commit 4529159

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

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

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

+21-7
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
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.
2525
* Author: Gravity Wiz
26-
* Version: 0.3
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
/**
@@ -44,6 +45,8 @@
4445
if ( preg_match( '/meta_([^0-9]+)_([0-9]+)_(.+)/', $key, $matches ) ) {
4546
list( , $repeater, $index, $subfield ) = $matches;
4647
$map[ $template ] = $subfield;
48+
} else {
49+
$custom_map[ $template ] = $key;
4750
}
4851
}
4952

@@ -64,16 +67,27 @@
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
}

0 commit comments

Comments
 (0)