|
23 | 23 | * Plugin URI: https://gravitywiz.com/documentation/gravity-forms-populate-anything/
|
24 | 24 | * Description: Populate all rows from an ACF Repeater into a choice-based field.
|
25 | 25 | * Author: Gravity Wiz
|
26 |
| - * Version: 0.3 |
| 26 | + * Version: 0.4 |
27 | 27 | * Author URI: https://gravitywiz.com
|
28 | 28 | */
|
29 | 29 | add_filter( 'gppa_input_choices', function( $choices, $field, $objects ) {
|
|
32 | 32 | return $choices;
|
33 | 33 | }
|
34 | 34 |
|
35 |
| - $map = array(); |
| 35 | + $map = array(); |
| 36 | + $custom_map = array(); |
36 | 37 |
|
37 | 38 | foreach ( $field->{'gppa-choices-templates'} as $template => $key ) {
|
38 | 39 | /**
|
|
44 | 45 | if ( preg_match( '/meta_([^0-9]+)_([0-9]+)_(.+)/', $key, $matches ) ) {
|
45 | 46 | list( , $repeater, $index, $subfield ) = $matches;
|
46 | 47 | $map[ $template ] = $subfield;
|
| 48 | + } else { |
| 49 | + $custom_map[ $template ] = $key; |
47 | 50 | }
|
48 | 51 | }
|
49 | 52 |
|
|
64 | 67 |
|
65 | 68 | if ( $rows ) {
|
66 | 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'] ); |
| 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 | + |
67 | 78 | $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, |
70 | 81 | );
|
| 82 | + |
71 | 83 | if ( isset( $map['inventory_limit'] ) ) {
|
72 | 84 | $choice['inventory_limit'] = apply_filters( 'gppa_acfrm_inventory_limit', rgar( $row, $map['inventory_limit'] ), $row, $map['inventory_limit'] );
|
73 | 85 | }
|
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 | + |
77 | 91 | $choices[] = $choice;
|
78 | 92 | }
|
79 | 93 | }
|
|
0 commit comments