acf_process_block_toolbar_fields()ACF 1.0

This function prepares a fields array for being localized and used on the frontend as block toolbar fields.

No Hooks.

Returns

Array. The array of fields, prepared for JS localization.

Usage

acf_process_block_toolbar_fields( $fields );
$fields(array) (required)
Array { Required. A list of the fields, each of which which will be displayed in the popup toolbar.

Each field can be passed as:

  • A string (e.g. 'my_field_name')
  • An associative array with specific keys:
@type string $field_name  The name of the field to display in the toolbar.
@type string $field_icon  An html tag, can be an svg, to be used as the toolbar icon. If not passed, the icon of the first field will be used.
@type string $field_label A string to use as the label for the button in the toolbar.

}.

acf_process_block_toolbar_fields() code ACF 6.8.8

function acf_process_block_toolbar_fields( $fields ) {
	$fields_processed = array();

	foreach ( $fields as $index => $field ) {
		if ( is_array( $field ) ) {
			$fields_processed[] = array(
				'fieldName'  => ! empty( $field['field_name'] ) ? $field['field_name'] : $index,
				// Base64 allows us to embed html in an attribute without causing issues with quotes, etc.
				'fieldIcon'  => ! empty( $field['field_icon'] ) ? base64_encode( $field['field_icon'] ) : null, // phpcs:ignore
				'fieldLabel' => ! empty( $field['field_label'] ) ? $field['field_label'] : null,
			);
		} else {
			$fields_processed[] = $field;
		}
	}

	return $fields_processed;
}