ACF Table Field Pro Add-on Docs Last updated:

Since version: v1.8.0

Release Candidate 1.8.0-RC1

This page documents version 1.8.0, which is available as Release Candidate 1.8.0-RC1 for manual installation. The current public version is 1.7.6, automatic plugin updates still deliver that version.

Download the Release Candidate from your account (Download the plugin) and install it manually (Install the plugin). Details may still change until the final release.

Filter acf_tablefield/formatting/areas

New since version 1.8.0

This filter is new.

This filter changes the list of the formatting areas. An area is a group of cells that carries its own formatting values on the table level, for example the head or the stub column. The plugin has four areas: head, stub, body and foot. With this filter you can remove an area or add your own, for example one for every second row. See cell formatting for how areas fit into the inheritance of the values.

The values of an area are stored on the table level with the key fm.<key>.<option>, for example fm.h.fw, and are named with the prefix of the area in the Table Manager, for example head_font_weight. For a cell, the areas that cover it are checked after the cell, the row and the column and before the table, in the order of their priority.

Areas you add have no controls in the table editor

An area you add with this filter has no panel in the overlay of the table settings. Its values cannot be set in the table editor. Set them with the Table Manager or in the table data, for example through the REST API. The REST schema offers the options of an added area, and the table output and the table editor apply its values to the cells it covers.

Set the PHP and the JavaScript filter the same way

If an area uses covers, the table editor needs the JavaScript counterpart to show the same cells as formatted as the website does: the JS filter formatting / area_covers. Without it, the editor falls back to sections, columns and table_options of the area.

Parameters

add_filter( 'acf_tablefield/formatting/areas', function( $areas ) { 
 
	// an area for every second row of the body 
	$areas['zb'] = array( 
		'key'      => 'zb', 
		'prefix'   => 'zebra_', 
		'label'    => 'Zebra', 
		'priority' => 25, 
		'sections' => array( 'b' ), 
		'covers'   => function( $table_data, $section_key, $row_index, $col_index ) { 
 
			return 'b' === $section_key && 1 === $row_index % 2; 
		}, 
	); 
 
	// an area for the third column in all sections 
	$areas['tc'] = array( 
		'key'      => 'tc', 
		'prefix'   => 'third_col_', 
		'label'    => 'Third column', 
		'priority' => 26, 
		'sections' => array( 'h', 'b', 'f' ), 
		'columns'  => array( 2 ), 
	); 
 
	return $areas; 
} );
    • $areas
    • (array)
    • The areas, the array keys are the area keys. Every area is an array with the entries listed below. The default areas are h (head), s (stub), b (body) and f (foot). An invalid area is dropped. The array key is used as key if the entry key is missing.

Area entries

Entries of an area

Entry Type Description
key string One or two characters from a-z and 0-9, unique. It becomes part of the stored key: fm.<key>.<option>.
prefix string The prefix of the Table Manager names of the area, for example totals_ for totals_font_weight. Characters a-z, 0-9 and _, ending with _. Required.
label string The name of the area. Default is the key.
priority integer The areas that cover a cell are checked from the lowest to the highest priority, the first value found wins. Areas with the same priority keep the order in which they were added. Default 10.
sections array The sections the area covers: h (head), b (body) and f (foot). At least one is required.
columns
array null
The columns the area covers, as a list of indexes starting at 0, or null for all columns. Default null.
table_options array Options of the table that must have the given stored value for the area to apply, for example array( 'sc' => 'y' ). All entries must match, values are compared as strings. Default is an empty array.
covers callable Optional. A function ( $table_data, $section_key, $row_index, $col_index ) that returns true if the area covers the cell. It replaces sections, columns and table_options in the check. The indexes start at 0, the row index counts within the section.

Default areas

Default areas

Key Prefix Priority Sections Columns Table options
h head_ 10 h all
s stub_ 20 h b f 0 sc is y (stub column on)
b body_ 30 b all
f foot_ 30 f all

The areas are read once, after the action after_setup_theme. Add the filter in a plugin or in the functions.php of the theme, not later. The list also decides which area keys the REST schema and the Table Manager know. Values of an area that is removed stay in the table data and have no effect.

Previous and Next Sources

Parent sources