ACF Template Builder

Adding shortcode attributes

You can add your custom attributes to be handled by the ACF fields. For this you will need to add the attribute to the field-type that handles the output. When that's done, you can add or replace the output-filters to use that attributes value.

Adding the attribute to the field-type

Add the attribute my merging it with the existing attributes that are used by a specific field-type:

add_filter( 'bbacf/helpers/sc_attr/type=google_map' , 'add_color_sc_attribute' );

/**
 * add the postid attribute to the default sc attr
 * @param  [type] $array [description]
 * @return [type]        [description]
 */
function add_color_sc_attribute( $array ) {
	return array_merge(
				$array,
				array(
                    'color'		=> null,
                    )
 			);
}

Using the attribute

When the field-type has the custom attributes applied, it will be able to pass those attributes to the output-filters. You can now write your callbacks to use those attributes.

The following example will add a colored border around a google_map field-type, whenever a color-attribute has been provided and is set.

add_filter( 'bbacf/helpers/get_acf_field/type=google_map'     ,       'add_red_border' , 11, 5 );

/**
 * add a colored border, using the added sc attr color
 * @param [type] $string       [description]
 * @param [type] $field_object [description]
 * @param [type] $value        [description]
 * @param [type] $atts         [description]
 * @param [type] $postid       [description]
 */
function add_red_border ( $string , $field_object , $value , $atts , $postid ) {
    if ( $atts[ 'color' ] !== null ) return '<div style="border:2px solid '.$atts[ 'color' ].'">' . $string . '</div>';
    return $string;
}