submission['fields'];
}
// Find all merge tags
if ( preg_match_all( "/{(.*?)}/", $input, $matches ) ) {
foreach ( $matches[1] as $i=>$tag ) {
// Resolve each merge tag and insert the value
$value = apply_filters( 'af/merge_tags/resolve', '', $tag, $fields );
$input = str_replace( $matches[0][ $i ], $value, $input );
}
}
return $input;
}
/**
* Renders a single field include (for emails, success messages etc.)
*
* @since 1.2.0
*
*/
function _af_render_field_include( $field, $value = false ) {
if ( ! $value ) {
$value = $field['value'];
}
$output = '';
if ( 'repeater' == $field['type'] && is_array( $value ) ) {
$output .= '
';
foreach ( $value as $row ) {
$row_layout_name = $row['acf_fc_layout'];
// Find layout based on name
$row_layout = NULL;
foreach ( $field['layouts'] as $layout ) {
if ( $layout['name'] === $row_layout_name ) {
$row_layout = $layout;
break;
}
}
// Output header with layout name for the row
$output .= sprintf( '| %s |
', $layout['label'] );
$output .= '';
// The subfield values will be displayed in a nested table, similar to a group field
$output .= '';
foreach ( $layout['sub_fields'] as $sub_field ) {
if ( isset( $row[ $sub_field['name'] ] ) ) {
$output .= sprintf( '| %s | ', $sub_field['label'] );
$output .= sprintf( '| %s | ', _af_render_field_include( $sub_field, $row[ $sub_field['name'] ] ) );
}
}
$output .= ' ';
$output .= ' |
';
}
$output .= '
';
} elseif ( 'clone' == $field['type'] || 'group' == $field['type'] ) {
$output .= sprintf( '';
foreach ( $field['sub_fields'] as $sub_field ) {
_af_field_inserter_render_option( $sub_field, $ancestors );
}
echo '
';
}
}
/**
* Generates choices for a form field picker.
* Returns an array with field key => field label suitable for usage with an ACF select field.
*
* $type can be either 'all' or 'regular'.
*
* @since 1.3.0
*
*/
function _af_form_field_choices( $form_key, $type = 'all' ) {
$form_fields = af_get_form_fields( $form_key, $type );
$choices = array();
if ( ! empty( $form_fields ) ) {
foreach ( $form_fields as $field ) {
$choices[ $field['key'] ] = $field['label'];
}
}
return $choices;
}
/**
* Find a nested sub field based on some selector.
* If the selector is ["g1", "g2", "f1"] then the function will find a
* field named "f1" inside "g2" which is inside field "g1".
* The $field parameter should be the top-level field, "g1" in the example.
*
* @since 1.7.2
*
*/
function af_pick_sub_field( $field, $selector ) {
while ( ! empty( $selector ) && $field && isset( $field['sub_fields'] ) ) {
$search = array_shift( $selector );
$field = acf_search_fields( $search, $field['sub_fields'] );
}
return $field;
}
/**
* Find a nested value of a sub field based on some selector.
* If the selector is ["g1", "g2", "f1"] then the function will return the
* value of field "f1" inside "g2" which is inside "g1".
* The $field parameter should be the top-level field, "g1" in the example.
*
* @since 1.7.2
*
*/
function af_pick_sub_field_value( $field, $selector ) {
$value = $field['value'];
while ( ! empty( $selector ) ) {
$search = array_shift( $selector );
if ( isset( $value[ $search ] ) ) {
$value = $value[ $search ];
} else {
return false;
}
}
return $value;
}
/**
* Retrieves full URL (with trailing slash) to the plugin assets folder
*
* @since 1.3.0
*
*/
function af_assets_url( $path = '' ) {
return plugin_dir_url( dirname( __FILE__ ) ) . 'assets/' . $path;
}