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
Loads table field data into the manager for processing. Stores the field data in: $table->field_data
.
Parameters
$table->get_field( $selector, [$post_id = false] );
-
$selector
The field name or field key.
-
$post_id
-
Defaults:
false
The post ID where the value is saved. Defaults to
false
, which will use the current post.
Get sub field
Loading a tablefields data from a sub field into the manager to work with. Stores the field data in: $table->$field_data
Parameters
$table->get_sub_field( $selector );
-
$selector
- Defaults:
The field name or field key.
Set table data
Passes the manager table data (formatted or unformatted) to work with. The data should come from get_field()
or get_sub_field()
. Stores the field data in: $table->field_data
.
Parameters
$table->set_table_data( $table_data );
-
$table_data
The data should come from
get_field()
orget_sub_field()
.
Update field
This saves the table data of the manager class to the database entry of the field.
Parameters
$table->update_field( $selector, $post_id );
-
$selector
The field key or field name. Not required if
$table->get_field()
of the table manager was used previously.
-
$post_id
A post ID or a variant for different objects like in
get_field()
. Not required if$table->get_field()
of the table manager was used previously.
Update sub field
Parameters
$table->update_sub_field( $selector );
-
$selector
The field key or field name. Not required if
$table->get_sub_field()
of the table manager was used previously.
Get table
Returns the table HTML.
echo $table->get_table();
Reset table
Resets the table data to default.
$table->reset_table();
Field settings
// 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
Parameters
$param = array(
'index' => $index,
'num_rows' => $num_rows,
);
$table->add_row( $param );
-
$index
- Defaults: If no index or an invalid index is specified, the rows are inserted at the end of the table.
The index at which the rows should be inserted. Starting from
0
.
-
$num_rows
-
Defaults:
1
The number of rows to add.
Add column
Parameters
$param = array(
'index' => $index,
'num_columns' => $num_columns,
);
$table->add_column( $param );
-
$index
- Defaults: If no index or an invalid index is specified, the columns are inserted at the end/right of the table.
The index at which the columns should be inserted. Starting from
0
.
-
$num_columns
-
Defaults:
1
The number of columns to add.
Remove row
Parameters
$param = array(
'index' => $index,
'num_rows' => $num_rows,
);
$table->remove_row( $param );
-
$index
-
Defaults:
null
If no index or an invalid index is specified, the rows are removed from the bottom of the table. The index at which the rows should be removed. Starting from
0
.
-
$num_rows
-
Defaults:
1
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
Parameters
$param = array(
'index' => $index,
'num_columns' => $num_columns,
);
$table->remove_column( $param );
-
$index
-
Defaults:
null
If no index or an invalid index is specified, the columns are removed from the end/right of the table. The index at which the columns should be removed. Starting from
0
.
-
$num_columns
-
Defaults:
1
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.
Move row
Parameters
$param = array(
'from' => $from,
'to' => $to,
);
$table->move_row( $param );
-
$from
The index of the body row that should be moved. Starting from
0
.
-
$to
The index where the body row should be moved. Starting from
0
.
Move column
Parameters
$param = array(
'from' => $from,
'to' => $to,
);
$table->move_column( $param );
-
$from
The index of the column that should be moved. Starting from
0
.
-
$to
The index where the column should be moved. Starting from
0
.
Data
The data()
method works like an API. Data from different table sections can be read and changed.
Parameters
$param = array(
'action' => $action,
'name' => $name,
//'section' => $section, // dependently required
//'col' => $col, // dependently required
//'row' => $row, // dependently required
//'value' => $value, // dependently required
);
$result = $table->data( $param );
-
$action
- Options:
get
,update
,add
,remove
,unset
Defines the action to perfom.
-
$name
-
Defaults:
null
(returns all data) 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
-
Defaults:
null
- Options:
table
,columns
,head
,body
,foot
Defines the data section to get the data from. This is dependently required.
-
$value
-
Defaults:
null
Defines a value to
update
,add
orremove
.
-
$row
-
Defaults:
null
Defines the row index of the table
body
section. This is required when processing data from a body row or cell.
-
$col
-
Defaults:
null
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
$content_type = $table->data( [
'action' => 'get',
'name' => 'content_type',
'section' => $section,
// 'col' => $col, // dependently required
// 'row' => $row, // dependently required
] );
-
$section
- Options:
table
,columns
,body
,head
,foot
-
$col
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
Required if you want to process data from a cell in section
body
.
Return
- Type: string
- Options:
empty string,
none
,st
,ed
Update content type
$table->data( [
'action' => 'update',
'name' => 'content_type',
'section' => $section,
'value' => $value,
'col' => $col, // required for column data for section column and cell data for sections body, head, foot.
'row' => $row, // required for row data on section body
] );
-
$section
- Options:
table
,columns
,body
,head
,foot
-
$value
- Options:
$value Description none
Table content not editable st
Simple text editing ed
WordPress classic editor (customizable toolbar)
-
$col
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
Required if you want to process data from a cell in section
body
.
Unset content type
$table->data( [
'action' => 'unset',
'name' => 'content_type',
'section' => $section,
'col' => $col, // required for column data for section column and cell data for sections body, head, foot.
'row' => $row, // required for row data on section body
] );
-
$section
- Options:
columns
,body
,head
,foot
The content type of the section
table
can not be unset.
-
$col
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
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
$wp_editor_toolbar = $table->data( [
'action' => 'get',
'name' => 'wp_editor_toolbar',
'section' => $section,
'col' => $col, // required for column data for section column and cell data for sections body, head, foot.
'row' => $row, // required for row data on section body
] );
-
$section
- Options:
table
,columns
,body
,head
,foot
Update WP editor toolbar
$table->data( [
'action' => 'update',
'name' => 'wp_editor_toolbar',
'section' => $section,
'value' => $value,
'col' => $col, // required for column data for section column and cell data for sections body, head, foot.
'row' => $row, // required for row data on section body
] );
-
$section
- Options:
table
,columns
,body
,head
,foot
-
$value
- Options:
basic
,full
, or custom toolbars
Unset WP editor toolbar
$table->data( [
'action' => 'unset',
'name' => 'wp_editor_toolbar',
'section' => $section,
'col' => $col, // required for column data for section column and cell data for sections body, head, foot.
'row' => $row, // required for row data on section body
] );
-
$section
- Options:
columns
,body
,head
,foot
The data in the
table
section is required and cannot be unset.
-
$col
Required if you want unset from a cell in section
head
,body
andfoot
. Also required when unsetting with thecolumns
section.
-
$row
Required if you want to unset from a cell with the
body
section.
styles
Get styles
$styles = $table->data( [
'action' => 'get',
'name' => 'styles',
'section' => $section,
// 'col' => $col, // dependently required
// 'row' => $row, // dependently required
] );
-
$section
- Options:
table
,columns
,body
,head
,foot
-
$col
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
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 styles
$table->data( [
'action' => 'update',
'name' => 'styles',
'section' => $section,
'value' => $value,
// 'col' => $col, // dependently required
// 'row' => $row, // dependently required
] );
-
$section
- Options:
table
,columns
,body
,head
,foot
-
$value
A string of CSS class names separated by spaces.
-
$col
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
Required if you want to process data from a cell in section
body
.
Add styles
$table->data( [
'action' => 'add',
'name' => 'styles',
'section' => $section,
'value' => $value,
// 'col' => $col, // dependently required
// 'row' => $row, // dependently required
] );
-
$section
- Options:
table
,columns
,body
,head
,foot
-
$value
The CSS class name to be added.
-
$col
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
Required if you want to process data from a cell in section
body
.
Remove styles
$table->data( [
'action' => 'remove',
'name' => 'styles',
'section' => $section,
'value' => $value,
// 'col' => $col, // dependently required
// 'row' => $row, // dependently required
] );
-
$section
- Options:
table
,columns
,body
,head
,foot
-
$value
The CSS class name to be removed.
-
$col
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
Required if you want to process data from a cell in section
body
.
Unset styles
$table->data( [
'action' => 'unset',
'name' => 'styles',
'section' => $section,
'col' => $col,
'row' => $row,
] );
-
$section
- Options:
columns
,body
,head
,foot
-
$col
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
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
$use_header = $table->data( [
'action' => 'get',
'name' => 'use_header',
'section' => 'table',
] );
Update use_header
$table->data( [
'action' => 'update',
'name' => 'use_header',
'section' => 'table',
'value' => $value,
] );
-
$value
- Options:
y
,n
use_footer
Values
$value | Description |
---|---|
y
|
Table footer is used |
n
|
Table footer is not used |
Update use_footer
-
$value
- 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
$use_stub_column = $table->data( [
'action' => 'get',
'name' => 'use_stub_column',
'section' => 'table',
] );
Update use_stub_column
$table->data( [
'action' => 'update',
'name' => 'use_stub_column',
'section' => 'table',
'value' => $value,
] );
-
$value
- Options:
y
,n
caption
Get caption
$caption = $table->data( [
'action' => 'get',
'name' => 'caption',
'section' => 'table',
] );
Update caption
$table->data( [
'action' => 'update',
'name' => 'caption',
'section' => 'table',
'value' => $value,
] );
-
$value
Caption text
col_width
Get col_width
$col_width = $table->data( [
'action' => 'get',
'name' => 'col_width',
'section' => 'columns',
'col' => $col,
] );
-
$col
Index of the column
Return
- Type: mixed
- Options:
$integer
,null
- Description:
Returns
null
if the setting is not set
Update col_width
$table->data( [
'action' => 'update',
'name' => 'col_width',
'section' => 'columns',
'value' => $value,
'col' => $col,
] );
-
$col
Index of the column
-
$value
Size in pixel
Unset col_width
$table->data( [
'action' => 'unset',
'name' => 'col_width',
'section' => 'columns',
'col' => $col,
] );
-
$col
Index of the column
col_min_width
Get col_min_width
$col_min_width = $table->data( [
'action' => 'get',
'name' => 'col_min_width',
'section' => 'columns',
'col' => $col,
] );
-
$col
Index of the column
Return
- Type: mixed
- Options:
$integer
,null
- Description:
Returns
null
if the setting is not set
Update col_min_width
$table->data( [
'action' => 'update',
'name' => 'col_min_width',
'section' => 'columns',
'value' => $value,
'col' => $col,
] );
-
$col
Index of the column
-
$value
Size in pixel
Unset col_min_width
$table->data( [
'action' => 'unset',
'name' => 'col_min_width',
'section' => 'columns',
'col' => $col,
] );
-
$col
Index of the column
colspan
Get colspan
$content = $table->data( [
'action' => 'get',
'name' => 'colspan',
'section' => $section,
'col' => $col_index,
'row' => $row_index, // dependently required
] );
-
$section
- Options:
body
,head
,foot
-
$col
-
$row
Required if you want to get data from a cell in section
body
.
Update colspan
$content = $table->data( [
'action' => 'update',
'name' => 'colspan',
'section' => $section,
'col' => $col_index,
'row' => $row_index, // dependently required
'value' => $value,
] );
-
$section
- Options:
body
,head
,foot
-
$col
-
$row
Required if you want to update data from a cell in section
body
.
-
$value
Amount of columns to span starting from 2.
Unset colspan
$content = $table->data( [
'action' => 'unset',
'name' => 'colspan',
'section' => $section,
'col' => $col_index,
'row' => $row_index, // dependently required
] );
-
$section
- Options:
body
,head
,foot
-
$col
-
$row
Required if you want to unset data from a cell in section
body
.
rowspan
Get rowspan
$content = $table->data( [
'action' => 'get',
'name' => 'rowspan',
'section' => $section,
'col' => $col_index,
'row' => $row_index, // dependently required
] );
-
$section
- Options:
body
,head
,foot
-
$col
-
$row
Required if you want to get data from a cell in section
body
.
Update rowspan
$content = $table->data( [
'action' => 'update',
'name' => 'rowspan',
'section' => $section,
'col' => $col_index,
'row' => $row_index, // dependently required
'value' => $value,
] );
-
$section
- Options:
body
,head
,foot
-
$col
-
$row
Required if you want to update data from a cell in section
body
.
-
$value
Amount of columns to span starting from 2.
Unset rowspan
$content = $table->data( [
'action' => 'unset',
'name' => 'rowspan',
'section' => $section,
'col' => $col_index,
'row' => $row_index, // dependently required
] );
-
$section
- Options:
body
,head
,foot
-
$col
-
$row
Required if you want to unset data from a cell in section
body
.
content
Get content
$content = $table->data( [
'action' => 'get',
'name' => 'content',
'section' => $section,
'col' => $col_index,
'row' => $row_index, // dependently required
] );
-
$section
- Options:
body
,head
,foot
-
$col
-
$row
Required if you want to get data from a cell in section
body
.
Update content
$table->data( [
'action' => 'update',
'name' => 'content',
'section' => $section,
'value' => $value,
'col' => $col,
'row' => $row, // dependently required
] );
-
$section
- Options:
body
,head
,foot
-
$col
-
$row
Required if you want to update data from a cell in section
body
.
-
$value
Text or HTML string
rows
$table->data( [
'action' => 'get',
'name' => 'rows',
'section' => 'table',
] );
Return
- Type: integer
- Description:
Returns the amount of table body rows.
cols
$table->data( [
'action' => 'get',
'name' => 'cols',
'section' => 'table',
] );
Return
- Type: integer
- Description:
Returns the amount of table columns.
field_key
$table->data( [
'action' => 'get',
'name' => 'field_key',
] );
Return
- Type: integer
- Description:
Returns the field key.
field_name
$table->data( [
'action' => 'get',
'name' => 'field_name',
] );
Return
- Type: integer
- Description:
Returns the field name.
plugin_version
$table->data( [
'action' => 'get',
'name' => 'plugin_version',
] );
Return
- Type: integer
- Description:
Returns the plugin version that was used to make the last table change.