This page lists the public PHP API, the shortcode and block, the hooks and the front-end script API. Use the functions in functions.php from themes and other plugins. The classes behind them may change.
Table data
Tables are stored as a custom post type, and read and written through functions. A table array looks like this:
array(
'id' => 3, // Table number.
'post_id' => 118,
'name' => 'Pricing',
'description' => '',
'data' => array( array( 'Plan', 'Price' ), array( 'Pro', '$12' ) ), // Rows of cell HTML. Row 0 is the header row when options['table_head'] is 1.
'visibility' => array( 'rows' => array( 1, 1 ), 'columns' => array( 1, 1 ) ), // 1 = shown, 0 = hidden.
'options' => array( 'table_head' => 1, 'highlight' => 0, 'highlight_label' => '', 'search_min' => 8, 'sortable' => 1, 'extra_css_classes' => '', 'column_types' => array( 'auto', 'auto' ) ),
'modified' => 1790000000, // Unix time.
'author' => 1, // Last editor.
)
Column types are auto, text, number, date, link and key.
PHP API
nitida_tables_ids()returns the table numbers.nitida_tables_exists( $id )returns true if the table exists.nitida_tables_get( $id )returns the table array, ornull.nitida_tables_save( $id, $patch, $expected_modified = null )updates a table.$patchmay containname,description,data,visibilityandoptions. Options are merged with the saved ones. It returnsarray( 'ok' => bool, 'error' => string, 'modified' => int ).nitida_tables_create( $name, $data = null, $id = 0, $description = '', $visibility = null, $options = null )creates a table and returns its number, or 0 on failure. Pass$idto keep a specific number. Without data you get a two-column starter table.nitida_tables_render( $id )returns the HTML of a table and loads the front-end assets. It returns an empty string when the table is missing.
Pass $expected_modified to refuse an update when the table changed in between:
$table = nitida_tables_get( 3 );
$table['data'][1][1] = '$14';
$res = nitida_tables_save( 3, array( 'data' => $table['data'] ), $table['modified'] );
if ( ! $res['ok'] ) {
// Someone else saved first. Read the table again and retry.
error_log( $res['error'] );
}
The two REST routes nitida-tables/v1/tables and nitida-tables/v1/tables/{id} are read-only and require the edit_posts capability. The block editor uses them.
Shortcode and block
The shortcode is [nitida_table id="1"]. id is the only attribute. If compat_shortcode is on in the settings, [table id="1"] works the same way. With Pro, [nitida_chart id="1"] draws the chart of a table, see Display features.
The block is nitida-tables/table. It is rendered on the server and has one attribute, id (number). It supports wide and full alignment.
Actions
nitida_tables_saved( $id, $table ): after a table was created or saved (editor, import, revision restore or API).nitida_tables_deleted( $id ): after a table was deleted.nitida_tables_imported( $id, $data ): after a file, HTML or pasted import created a table.nitida_tables_created_from_template( $id, $template ): after a table was created from a template.nitida_tables_migrated( $source_key, $result ): after tables of another plugin were copied.nitida_tables_migrate_takeover( $source_key, $on ): when “Keep old shortcodes working” is switched.nitida_tables_flush_post_cache( $post_id, $table_id ): for each post that uses a saved table, so you can purge your page cache.
Admin screen hooks (print escaped HTML):
nitida_tables_editor_top( $table )andnitida_tables_editor_sidebar( $table )in the table editor.nitida_tables_list_after_toolbar,nitida_tables_list_row_badges( $id, $table )andnitida_tables_list_name_after( $id, $table )on the table list.nitida_tables_migrate_top( $scan )on the migration assistant.
Filters: settings and admin
nitida_tables_capability: the capability needed to create and edit tables. It starts from the “Who can create and edit tables” setting.nitida_tables_pre_save( $pre, $id, $patch, $expected ): return an array withmessageto stop an editor save without changing the table.nitida_tables_templates: the list of templates on Add new.nitida_tables_migrate_sources: the list of migration sources.nitida_tables_import_highlight_ids: table numbers that get the first-row highlight when imported from TablePress.nitida_tables_menu_titleandnitida_tables_title_badges: the menu label and the badges after screen titles.nitida_tables_show_core_notice: set to false to hide the Pro notice about WordPress table blocks.
Filters: rendering
nitida_tables_column_kind( $kind, $header, $index, $table ): the kind of a column (title,key,number,date,linkortext).nitida_tables_cell_label( $label, $index, $table ): the label shown on cards. It defaults to the header text.nitida_tables_table_html_id( $id, $table ): the HTML id of the grid.nitida_tables_wrapper_attributes( $attrs, $table, $ctx ): attributes of the wrapperdiv.classis an array.nitida_tables_before_table( $html, $table, $ctx, $info )andnitida_tables_after_table( ... ): HTML inside the wrapper before the search bar and after the table.nitida_tables_header_cell_attributes( $attrs, $cell, $index, $table ): attributes of a header cell.nitida_tables_body_rows( $rows, $table, $ctx, $info ): the data rows, before they are drawn.nitida_tables_row_attributes( $attrs, $row, $row_index, $table, $info ): attributes of a row.nitida_tables_cell_attributes( $attrs, $raw, $col, $visible_col, $row, $kind, $table ): attributes of a cell.nitida_tables_cell_html( $html, $raw, $col, $kind, $table ): the cell content. It is already sanitized and must stay escaped.nitida_tables_table_html( $html, $table, $ctx ): the final HTML.
$ctx['context'] is shortcode, block, compat, api or preview. $info holds the visible columns, kinds, labels, header cells and rows.
add_filter( 'nitida_tables_cell_html', function ( $html, $raw, $col, $kind ) {
return 'number' === $kind ? '<span class="num">' . $html . '</span>' : $html;
}, 10, 4 );
Language and caching
nitida_tables_front_strings( $strings, $table, $rows ): the visitor stringssearch,rows,rows_filtered,highlight,emptyandclear.nitida_tables_page_locale( $locale ): the locale taken from<html lang>. Return an empty string to keep the site language.- Tables with 200 or more rows keep their rendered rows in a transient. Control it with
nitida_tables_render_cache_min_rows,nitida_tables_render_cache( $use, $table, $ctx )andnitida_tables_render_cache_salt( $salt, $table, $ctx ). Add to the salt if your row or cell filters depend on your own settings.
Pro hooks
nitida_tables_pro_feature_defaults,nitida_tables_pro_feature_sanitizeandnitida_tables_pro_feature_needs_assets: add a settings group of your own to the per-table Pro features.nitida_tables_pro_features_tabsandnitida_tables_pro_features_save_map, with the actionnitida_tables_pro_features_tab_{key}: add a tab to the Pro features screen.nitida_tables_pro_features_saved( $id ): after Pro settings were saved.nitida_tables_pro_synced( $id, $outcome ): after a data source run, with its status and message.nitida_tables_pro_updated_label: the “Last updated: %s” text.nitida_tables_pro_dataset_license: a license URL for the Dataset structured data.nitida_tables_pro_core_localeandnitida_tables_pro_groups_locale: the language used for phone strings of WordPress tables and for group sorting.
Front-end script API
The front-end script has no dependencies. When a table is ready, its wrapper (.nitida-table) fires a bubbling nitida:ready event. event.detail is the table API, which is also available as wrapper.nitidaTable:
wrapper,tableandrows(the body rows in their original order)refresh()applies the search and the filters, and returns the matching rowsaddFilter( fn )andremoveFilter( fn ):fn( row )returns true to keep a rowonChange( cb ):cb( rows )runs after every refresh with the matching rows
document.addEventListener( 'nitida:ready', function ( e ) {
var api = e.detail;
api.addFilter( function ( row ) {
return row.cells[1].textContent.indexOf( 'Pro' ) > -1;
} );
api.onChange( function ( rows ) {
console.log( rows.length + ' rows match' );
} );
api.refresh();
} );
Tables added to the page later, for example by AJAX, can be started with window.nitidaTablesInit( container ). Rows that are filtered out get the hidden attribute.