Select plugin version:
table_manager()
The table manager allows reading, rendering and modifying a table as well as updating a table field.
New table manager
Get table manager instance
$table = table_manager();
The table manager function returns an instance of the table manager class and provides methodes for managing a table. It starts with default table data.
Get field
Loading a tablefields data into the manager to work with.
Get field
$table->get_field( $selector, [$post_id = false] );
Parameters
-
$selector
- Type: string
- Default:
- Description:
The field name or field key.
-
$post_id
- Optional: yes
- Type: mixed
- Default: false
- Description:
The post ID where the value is saved. Defaults to false, which will use the current post.
Return
Stores the field data in: ACFTablefield::$field_data
Get sub field
$table->get_sub_field( $selector );
Parameters
-
$selector
- Type: string
- Default:
- Description:
The field name or field key.
Return
Stores the field data in: ACFTablefield::$field_data
Set table data
Passes the manager the data from a table (formatted or unformatted) to work with. The data should come from get_field()
or get_sub_field()
.
Set table data
$table->set_table_data( $table_data );
Parameters
-
$table_data
- Type: array
- Description:
The data should come from
get_field()
orget_sub_field()
.
Return
Stores the field data in: ACFTablefield::$field_data
or as in the example in $table->field_data
.
Update field
Update field
$table->update_field( $selector, $post_id );
This saves the table data of the manager class to the database entry of the field.
Parameters
-
$selector
- Optional: yes
- Type: string
- Description:
The field key or field name. Not required if
::get_field()
of the table manager was used previously.
-
$post_id
- Optional: yes
- Type: mixed
- Description:
A post ID or a variant for different objects like in
get_field()
. Not required if::get_field()
of the table manager was used previously.
Get table
Get table
echo $table->get_table();
Return
Returns the table HTML.
Reset table
Reset table
$table->reset_table();
Resets the table data to default.
Field settings
Get
// all settings
$settings = $table->get_field_settings();
// a specific setting
$min_columns = $table->get_field_settings( 'min_columns' );
Settings
Name | Type | Default | Values | Description |
---|---|---|---|---|
Limited columns and rows | ||||
min_columns
|
mixed |
0 Stands for no restriction.
|
Can be a number or empty. | Prevents columns from being removed when the minimum specified number of columns is reached. |
max_columns
|
mixed |
0 Stands for no restriction.
|
Can be a number or empty. | Prevents adding columns when the maximum specified number of columns is reached. |
min_rows
|
mixed |
0 Stands for no restriction.
|
Can be a number or empty. | Prevents rows from being removed when the minimum specified number of columns is reached. |
max_rows
|
mixed |
0 Stands for no restriction.
|
Can be a number or empty. | Prevents adding rows when the maximum specified number of columns is reached. |
Allowed editing functionalities for the different tool modals | ||||
table_tools
|
array |
|
Defines the editing functions and options for the table tools. | |
column_tools
|
array |
|
Defines the editing functions and options for the columns tools. | |
header_row_tools
|
array |
|
Defines the editing functions and options for the tbale header row tools. | |
header_cell_tools
|
array |
|
Defines the editing functions and options for the table header cells tools. | |
body_row_tools
|
array |
|
Defines the editing functions and options for the body rows tools. | |
body_cell_tools
|
array |
|
Defines the editing functions and options for the body cells tools. | |
footer_row_tools
|
array |
|
Defines the editing functions and options for the table footer row tools. | |
footer_cell_tools
|
array |
|
Defines the editing functions and options for the table footer cells tools. | |
Style choices | ||||
table_styles
|
array | The style choices for the table. | ||
column_styles
|
array | The style choices of a column. | ||
header_row_styles
|
array | The style choices of a header row. | ||
header_cell_styles
|
array | The style choices of a header cell. | ||
body_row_styles
|
array | The style choices of a body row. | ||
body_cell_styles
|
array | The style choices of a body cell. | ||
footer_row_styles
|
array | The style choices of a footer row. | ||
footer_cell_styles
|
array | The style choices of a footer cell. | ||
Default table | ||||
default_table_data
|
array | The raw table data of the default table. |
Add row
Add row
$param = array(
'index' => $index,
'num_rows' => $num_rows,
);
$table->add_row( $param );
Parameters
-
$index
- Optional: yes
- Type: integer, numeric string
- Default: If no index or an invalid index is specified, the rows are inserted at the end of the table.
- Description:
The index at which the rows should be inserted. Starting from
0
.
-
$num_rows
- Optional: yes
- Type: integer, numeric string
- Default:
1
- Description:
The number of rows to add.
Add column
Add column
$param = array(
'index' => $index,
'num_columns' => $num_columns,
);
$table->add_column( $param );
Parameters
-
$index
- Optional: yes
- Type: integer, numeric string
- Default: If no index or an invalid index is specified, the columns are inserted at the end/right of the table.
- Description:
The index at which the columns should be inserted. Starting from
0
.
-
$num_columns
- Optional: yes
- Type: integer, numeric string
- Default:
1
- Description:
The number of columns to add.
Remove row
Remove row
$param = array(
'index' => $index,
'num_rows' => $num_rows,
);
$table->remove_row( $param );
Parameters
-
$index
- Optional: yes
- Type: integer, numeric string,
null
- Default:
null
If no index or an invalid index is specified, the rows are removed from the bottom of the table. - Description:
The index at which the rows should be removed. Starting from
0
.
-
$num_rows
- Optional: yes
- Type: integer, numeric string
- Default:
1
- Description:
The number of rows to remove. If all rows are removed, a blank row is inserted afterwards. It is accepted if the number of rows to be removed may be higher than the number of existing rows.
Remove column
Remove column
$param = array(
'index' => $index,
'num_columns' => $num_columns,
);
$table->remove_column( $param );
Parameters
-
$index
- Optional: yes
- Type: integer, numeric string,
null
- Default:
null
If no index or an invalid index is specified, the columns are removed from the end/right of the table. - Description:
The index at which the columns should be removed. Starting from
0
.
-
$num_columns
- Optional: yes
- Type: integer, numeric string
- Default:
1
- Description:
The number of columns to remove. If all columns are removed, a blank column is inserted afterwards. It is accepted if the number of columns to be removed may be higher than the number of existing columns.
Data
The data()
method works like an API. Data from different table sections can be read and changed.
data()
$param = array(
'action' => $action,
'name' => $name,
//'section' => $section, // dependently required
//'row' => $row, // dependently required
//'col' => $col, // dependently required
//'value' => $value, // dependently required
);
$result = $table->data( $param );
Parameters
-
$action
- Type: string
- Options:
get
,update
,add
,remove
,unset
- Description:
Defines the action to perfom.
-
$name
- Optional: yes
- Type: string
- Default:
null
(returns all data) - Description:
Defines the data name. Some data need row and/or col parameter. If there is no name given, all data of the section are returned on a valid set of the other parameters.
-
$section
- Type: string
- Default:
null
- Options:
table
,columns
,head
,body
,foot
- Description:
Defines the data section to get the data from. This is dependently required.
-
$value
- Type: mixed
- Default:
null
- Description:
Defines a value to
update
,add
orremove
.
-
$row
- Optional: yes
- Type: integer
- Default:
null
- Description:
Defines the row index of the table
body
section. This is required when processing data from a body row or cell.
-
$col
- Optional: yes
- Type: integer
- Default:
null
- Description:
Defines the column index to process the data from. This is required for the
columns
section and for processing cell data on sectionshead
,body
andfoot
.
Return
On action get
: returns the data value or an array of data name/value pairs. If no valid parameters were given or the data value not exists, null
is returned. On action update
, add
, remove
: returns true
or false
depending on whether the data has been set.
Data actions
$action | Description | Data |
---|---|---|
get
|
Gets the data according to the other parameters. | all |
update
|
Updates the data by replacing it. If data not exists, it sets the data. | all |
add
|
Adds data to existing data. |
styles
|
remove
|
Removes data from existing data. |
styles
|
unset
|
Removes the data entry. | all |
Data sections
Description | Section | Parameters | $name |
---|---|---|---|
Field parameter |
|
field_key field_name plugin_version
|
|
All data of the table |
table
|
|
|
A specific data of the table |
table
|
|
use_header use_footer use_stub_column caption cols rows content_type wp_editor_toolbar styles
|
All data of a table column |
columns
|
|
|
A specific data of a table column |
columns
|
|
content_type wp_editor_toolbar styles col_width col_min_width
|
All data of the head row |
head
|
|
|
A specific data of the head row |
head
|
|
content_type wp_editor_toolbar styles
|
All data of a head cell |
head
|
|
|
A specific data of a head cell |
head
|
|
content_type wp_editor_toolbar styles colspan content
|
All data of the foot row |
foot
|
|
|
A specific data of the foot row |
foot
|
|
content_type wp_editor_toolbar styles
|
All data of a foot cell |
foot
|
|
|
A specific data of a foot cell |
foot
|
|
content_type wp_editor_toolbar styles colspan content
|
All data of a body row |
body
|
|
|
A specific data of the body row |
body
|
|
content_type wp_editor_toolbar styles
|
All data of a body cell |
body
|
|
|
A specific data of a body cell |
body
|
|
content_type wp_editor_toolbar styles colspan rowspan has_span content
|
Data names
Name | Sections | Type | Values | Actions | Description |
---|---|---|---|---|---|
use_header
|
table
|
string |
y n
|
get update
|
Wether the table header should be used. |
use_footer
|
table
|
string |
y n
|
get update
|
Wether the table footer should be used. |
use_stub_column
|
table
|
string |
y n
|
get update
|
Wether the table stub column should be used. |
caption
|
table
|
string |
get update
|
The table caption content. |
|
content_type
|
table columns body head foot
|
string | null
|
none st ed
|
get update unset * * not on section table
|
Returns the content type. |
wp_editor_toolbar
|
table body columns head foot
|
string | null
|
basic full , or custom toolbars
|
get update unset * * not on section table
|
Defines the editor toolbar. Requires |
styles
|
table body columns head foot
|
string | null
|
get update add remove unset * * not on section table
|
Defines a string of CSS classes separated by a space. |
|
col_width
|
columns
|
integer | null
|
get update unset
|
With of the column at the admin editing table. |
|
col_min_width
|
columns
|
integer | null
|
get update unset
|
Min with of the column at the admin editing table. |
|
colspan
|
body head foot
|
integer | null
|
get update unset
|
Amount of columns to span. |
|
rowspan
|
body
|
integer | null
|
get update unset
|
Amount of rows to span. |
|
has_span
|
body head foot
|
array | null
|
Coordinates of the spanning cell and its colspan and rowspan values.
|
get
|
If a cell is spanned, this returns an Array which contains the information about the column and row index of the originating cell and the span distances. This data is set automatically when |
content
|
body head foot
|
string |
get update
|
The cell content. |
|
cols
|
table
|
integer |
get
|
The current amount of table columns. |
|
rows
|
table
|
integer |
get
|
The current amount of table body rows. |
content_type
The content type defines the way in which the cell content is edited. It is permantently defined in the table section. If the content type is not set in a child setting, the content type is inherited from the parent setting.
Values
$value | Description |
---|---|
none
|
Table content not editable |
st
|
Simple text editing |
ed
|
WordPress classic editor (customizable toolbar) |
Get
$content_type = $table->data( [
'action' => 'get',
'name' => 'content_type',
'section' => $section,
// 'col' => $col, // dependently required
// 'row' => $row, // dependently required
] );
Parameters
-
$section
- Type: string
- Options:
table
,columns
,body
,head
,foot
-
$col
- Type: integer
- Description:
Required if you want to process data from a cell in section
head
,body
andfoot
. Also required when processing a columns data using sectioncolumns
.
-
$row
- Type: integer
- Description:
Required if you want to process data from a cell in section
body
.
Return
- Type: string
- Options:
empty string,
none
,st
,ed
Update
$table->data( [
'action' => 'update',
'name' => 'content_type',
'section' => $section,
'value' => $value,
'row' => $row, // required for row data on section body
'col' => $col, // required for column data for section column and cell data for sections body, head, foot.
] );
Parameters
-
$section
- Type: string
- Options:
table
,columns
,body
,head
,foot
-
$col
- Type: integer
- Description:
Required if you want to process data from a cell in section
head
,body
andfoot
. Also required when processing a columns data using sectioncolumns
.
-
$row
- Type: integer
- Description:
Required if you want to process data from a cell in section
body
.
Unset
$table->data( [
'action' => 'unset',
'name' => 'content_type',
'section' => $section,
'row' => $row, // required for row data on section body
'col' => $col, // required for column data for section column and cell data for sections body, head, foot.
] );
Parameters
-
$section
- Type: string
- Options:
columns
,body
,head
,foot
- Description:
The content type of the section
table
can not be unset.
-
$col
- Type: integer
- Description:
Required if you want to process data from a cell in section
head
,body
andfoot
. Also required when processing a columns data using sectioncolumns
.
-
$row
- Type: integer
- Description:
Required if you want to process data from a cell in section
body
.
wp_editor_toolbar
Values
$value | Description |
---|---|
empty string | If no WordPress editor toolbar value is set, then the value is inherited from the parent setting. A toolbar value is required for the table section. |
basic
|
Basic toolbar |
full
|
Full WordPress editor toolbar |
Get
$wp_editor_toolbar = $table->data( [
'action' => 'get',
'name' => 'wp_editor_toolbar',
'section' => $section,
] );
Parameters
-
$section
- Type: string
- Options:
table
,columns
,body
,head
,foot
Update
$table->data( [
'action' => 'update',
'name' => 'wp_editor_toolbar',
'section' => $section,
'value' => $value,
] );
Parameters
-
$section
- Type: string
- Options:
table
,columns
,body
,head
,foot
-
$value
- Type: string
- Options:
basic
,full
, or custom toolbars
styles
Get
$styles = $table->data( [
'action' => 'get',
'name' => 'styles',
'section' => $section,
// 'col' => $col, // dependently required
// 'row' => $row, // dependently required
] );
Parameters
-
$section
- Type: string
- Options:
table
,columns
,body
,head
,foot
-
$col
- Type: integer
- Description:
Required if you want to process data from a cell in section
head
,body
andfoot
. Also required when processing a columns data using sectioncolumns
.
-
$row
- Type: integer
- Description:
Required if you want to process data from a cell in section
body
.
Return
- Type: mixed
- Options:
$integer
,null
- Description:
Returns
null
if the setting is not set
Update
$table->data( [
'action' => 'update',
'name' => 'styles',
'section' => $section,
'value' => $value,
// 'col' => $col, // dependently required
// 'row' => $row, // dependently required
] );
Parameters
-
$section
- Type: string
- Options:
table
,columns
,body
,head
,foot
-
$value
- Type: string
- Description:
A string of CSS class names separated by spaces.
-
$col
- Type: integer
- Description:
Required if you want to process data from a cell in section
head
,body
andfoot
. Also required when processing a columns data using sectioncolumns
.
-
$row
- Type: integer
- Description:
Required if you want to process data from a cell in section
body
.
Add
$table->data( [
'action' => 'add',
'name' => 'styles',
'section' => $section,
'value' => $value,
// 'col' => $col, // dependently required
// 'row' => $row, // dependently required
] );
Parameters
-
$section
- Type: string
- Options:
table
,columns
,body
,head
,foot
-
$value
- Type: string
- Description:
The CSS class name to be added.
-
$col
- Type: integer
- Description:
Required if you want to process data from a cell in section
head
,body
andfoot
. Also required when processing a columns data using sectioncolumns
.
-
$row
- Type: integer
- Description:
Required if you want to process data from a cell in section
body
.
Remove
$table->data( [
'action' => 'remove',
'name' => 'styles',
'section' => $section,
'value' => $value,
// 'col' => $col, // dependently required
// 'row' => $row, // dependently required
] );
Parameters
-
$section
- Type: string
- Options:
table
,columns
,body
,head
,foot
-
$value
- Type: string
- Description:
The CSS class name to be removed.
-
$col
- Type: integer
- Description:
Required if you want to process data from a cell in section
head
,body
andfoot
. Also required when processing a columns data using sectioncolumns
.
-
$row
- Type: integer
- Description:
Required if you want to process data from a cell in section
body
.
Unset
$table->data( [
'action' => 'unset',
'name' => 'styles',
'section' => $section,
'col' => $col,
'row' => $row,
] );
Parameters
-
$section
- Type: string
- Options:
columns
,body
,head
,foot
-
$col
- Type: integer
- Description:
Required if you want to unset data from a cell in section
head
,body
andfoot
. Also required when getting a columns data using sectioncolumns
.
-
$row
- Type: integer
- Description:
Required if you want to unset data from a cell in section
body
.
use_header
Values
$value | Description |
---|---|
y
|
Table header is used |
n
|
Table header is not used |
Get
$use_header = $table->data( [
'action' => 'get',
'name' => 'use_header',
'section' => 'table',
] );
Update
$table->data( [
'action' => 'update',
'name' => 'use_header',
'section' => 'table',
'value' => $value,
] );
Parameters
-
$value
- Type: string
- Options:
y
,n
use_footer
Values
$value | Description |
---|---|
y
|
Table footer is used |
n
|
Table footer is not used |
Get
$use_footer = $table->data( [
'action' => 'get',
'name' => 'use_footer',
'section' => 'table',
] );
Update
$table->data( [
'action' => 'update',
'name' => 'use_footer',
'section' => 'table',
'value' => $value,
] );
Parameters
-
$value
- Type: string
- Options:
y
,n
use_stub_column
Values
$value | Description |
---|---|
y
|
Table stub column is used |
n
|
Table stub column is not used |
Get
$use_stub_column = $table->data( [
'action' => 'get',
'name' => 'use_stub_column',
'section' => 'table',
] );
Update
$table->data( [
'action' => 'update',
'name' => 'use_stub_column',
'section' => 'table',
'value' => $value,
] );
Parameters
-
$value
- Type: string
- Options:
y
,n
caption
Get
$caption = $table->data( [
'action' => 'get',
'name' => 'caption',
'section' => 'table',
] );
Update
$table->data( [
'action' => 'update',
'name' => 'caption',
'section' => 'table',
'value' => $value,
] );
Parameters
-
$value
- Type: string
- Description:
Caption text
col_width
Get
$col_width = $table->data( [
'action' => 'get',
'name' => 'col_width',
'section' => 'columns',
'col' => $col,
] );
Parameters
-
$col
- Type: integer
- Description:
Index of the column
Return
- Type: mixed
- Options:
$integer
,null
- Description:
Returns
null
if the setting is not set
Update
$table->data( [
'action' => 'update',
'name' => 'col_width',
'section' => 'columns',
'value' => $value,
'col' => $col,
] );
Parameters
-
$col
- Type: integer
- Description:
Index of the column
-
$value
- Type: integer
- Description:
Size in pixel
Unset
$table->data( [
'action' => 'unset',
'name' => 'col_width',
'section' => 'columns',
'col' => $col,
] );
Parameters
-
$col
- Type: integer
- Description:
Index of the column
col_min_width
Get
$col_min_width = $table->data( [
'action' => 'get',
'name' => 'col_min_width',
'section' => 'columns',
'col' => $col,
] );
Parameters
-
$col
- Type: integer
- Description:
Index of the column
Return
- Type: mixed
- Options:
$integer
,null
- Description:
Returns
null
if the setting is not set
Update
$table->data( [
'action' => 'update',
'name' => 'col_min_width',
'section' => 'columns',
'value' => $value,
'col' => $col,
] );
Parameters
-
$col
- Type: integer
- Description:
Index of the column
-
$value
- Type: integer
- Description:
Size in pixel
Unset
$table->data( [
'action' => 'unset',
'name' => 'col_min_width',
'section' => 'columns',
'col' => $col,
] );
Parameters
-
$col
- Type: integer
- Description:
Index of the column
content
Get
$content = $table->data( [
'action' => 'get',
'name' => 'content',
'section' => $section,
'col' => $col_index,
'row' => $row_index, // dependently required
] );
Parameters
-
$section
- Options:
body
,head
,foot
- Options:
-
$col
- Type: integer
-
$row
- Type: integer
- Description:
Required if you want to get data from a cell in section
body
.
Update
$table->data( [
'action' => 'update',
'name' => 'content',
'section' => $section,
'value' => $value,
'col' => $col,
'row' => $row, // dependently required
] );
Parameters
-
$section
- Type: string
- Options:
body
,head
,foot
-
$col
- Type: integer
-
$row
- Type: integer
- Description:
Required if you want to update data from a cell in section
body
.
-
$value
- Type: string
- Description:
Text or HTML string
rows
Get
$table->data( [
'action' => 'get',
'name' => 'rows',
'section' => 'table',
] );
Return
- Type: integer
- Description:
Returns the amount of table body rows.
cols
Get
$table->data( [
'action' => 'get',
'name' => 'cols',
'section' => 'table',
] );
Return
- Type: integer
- Description:
Returns the amount of table columns.
field_key
Get
$table->data( [
'action' => 'get',
'name' => 'field_key',
] );
Return
- Type: integer
- Description:
Returns the field key.
field_name
Get
$table->data( [
'action' => 'get',
'name' => 'field_name',
] );
Return
- Type: integer
- Description:
Returns the field name.
plugin_version
Get
$table->data( [
'action' => 'get',
'name' => 'plugin_version',
] );
Return
- Type: integer
- Description:
Returns the plugin version that was used to make the last table change.