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
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 */
2929add_filter ( 'gppa_input_choices ' , function ( $ choices , $ field , $ objects ) {
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 /**
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
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