Since version: v1.8.0
Filter acf_tablefield/formatting/areas
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.
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;
} );
-
$areasThe 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) andf(foot). An invalid area is dropped. The array key is used askeyif the entrykeyis 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
|
|
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.