Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gppa-acf-repeater-mapper.php: Added support for custom values with ACF field property template. #821

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions gp-populate-anything/gppa-acf-repeater-mapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* Plugin URI: https://gravitywiz.com/documentation/gravity-forms-populate-anything/
* Description: Populate all rows from an ACF Repeater into a choice-based field.
* Author: Gravity Wiz
* Version: 0.3
* Version: 0.4
* Author URI: https://gravitywiz.com
*/
add_filter( 'gppa_input_choices', function( $choices, $field, $objects ) {
Expand All @@ -32,7 +32,8 @@
return $choices;
}

$map = array();
$map = array();

Check failure on line 35 in gp-populate-anything/gppa-acf-repeater-mapper.php

View workflow job for this annotation

GitHub Actions / PHPCS (Files Changed)

Spaces must be used for mid-line alignment; tabs are not allowed
$custom_map = array();

foreach ( $field->{'gppa-choices-templates'} as $template => $key ) {
/**
Expand All @@ -43,7 +44,9 @@
*/
if ( preg_match( '/meta_([^0-9]+)_([0-9]+)_(.+)/', $key, $matches ) ) {
list( , $repeater, $index, $subfield ) = $matches;
$map[ $template ] = $subfield;
$map[ $template ] = $subfield;

Check failure on line 47 in gp-populate-anything/gppa-acf-repeater-mapper.php

View workflow job for this annotation

GitHub Actions / PHPCS (Files Changed)

Spaces must be used for mid-line alignment; tabs are not allowed

Check warning on line 47 in gp-populate-anything/gppa-acf-repeater-mapper.php

View workflow job for this annotation

GitHub Actions / PHPCS (Files Changed)

Equals sign not aligned with surrounding assignments; expected 22 spaces but found 21 spaces
} else {
$custom_map[ $template ] = $key;
}
}

Expand All @@ -64,16 +67,27 @@

if ( $rows ) {
foreach ( $rows as $row ) {
$label = isset( $map['label'] ) ?
apply_filters( 'gppa_acfrm_label', rgar($row, $map['label']), $row, $map['label'] ) :

Check failure on line 71 in gp-populate-anything/gppa-acf-repeater-mapper.php

View workflow job for this annotation

GitHub Actions / PHPCS (Files Changed)

Expected 1 spaces after opening parenthesis; 0 found

Check failure on line 71 in gp-populate-anything/gppa-acf-repeater-mapper.php

View workflow job for this annotation

GitHub Actions / PHPCS (Files Changed)

Expected 1 spaces before closing parenthesis; 0 found
str_replace( 'gf_custom:', '', $custom_map['label'] );

$value = isset( $map['value'] ) ?
apply_filters( 'gppa_acfrm_value', rgar( $row, $map['value']), $row, $map['value'] ) :

Check failure on line 75 in gp-populate-anything/gppa-acf-repeater-mapper.php

View workflow job for this annotation

GitHub Actions / PHPCS (Files Changed)

Expected 1 spaces before closing parenthesis; 0 found
str_replace( 'gf_custom:', '', $custom_map['value'] );

$choice = array(
'value' => apply_filters( 'gppa_acfrm_value', rgar( $row, $map['value'] ), $row, $map['value'] ),
'text' => apply_filters( 'gppa_acfrm_label', rgar( $row, $map['label'] ), $row, $map['label'] ),
'value' => $value,
'text' => $label,
);

if ( isset( $map['inventory_limit'] ) ) {
$choice['inventory_limit'] = apply_filters( 'gppa_acfrm_inventory_limit', rgar( $row, $map['inventory_limit'] ), $row, $map['inventory_limit'] );
}
if ( isset( $map['price'] ) ) {
$choice['price'] = apply_filters( 'gppa_acfrm_price', rgar( $row, $map['price'] ), $row, $map['price'] );
}

$choice['price'] = isset( $map['price'] ) ?
apply_filters( 'gppa_acfrm_price', rgar($row, $map['price']), $row, $map['price'] ) :

Check warning on line 88 in gp-populate-anything/gppa-acf-repeater-mapper.php

View workflow job for this annotation

GitHub Actions / PHPCS (Files Changed)

Found precision alignment of 2 spaces.
str_replace( 'gf_custom:', '', $custom_map['price'] );

Check warning on line 89 in gp-populate-anything/gppa-acf-repeater-mapper.php

View workflow job for this annotation

GitHub Actions / PHPCS (Files Changed)

Found precision alignment of 2 spaces.

$choices[] = $choice;
}
}
Expand Down
Loading