Hooks & Filters

TableCrafter exposes a small, focused set of extensibility points: two PHP apply_filters hooks for customizing export templates and proxy trust, plus three frontend JavaScript CustomEvents for reacting to mobile card interactions. This page documents every real hook with its exact signature.

PHP FiltersJS CustomEventsExport TemplatesProxy TrustCard Events

Overview

TableCrafter is intentionally lean on server-side hooks. Because the plugin fetches data from external sources rather than storing it in your database, most customization happens through shortcode attributes, CSS custom properties, and the frontend event system rather than through a large hook surface.

At version 3.5.6, the plugin defines exactly two PHP filters and emits three namespaced DOM events. There are no do_action hooks. This page covers all of them.

ℹ️

The shortcode tag is [tablecrafter] and the REST namespace is tablecrafter/v1. Filter and event names use the tc_ / tablecrafter_ / tablecrafter: prefixes shown below. No other hook prefixes exist in the codebase.

PHP Filters

Both PHP filters are standard WordPress apply_filters hooks. Register your callbacks with add_filter() from your theme's functions.php or a small companion plugin.

FilterDefined inPurpose
tc_export_templatesOptional includes/class-tc-export-handler.phpAdd or modify named export formatting presets.
tablecrafter_trusted_ip_headersOptional includes/class-tc-security.phpOpt in to trusting specific proxy/load-balancer IP headers.

tc_export_templates

Filters the array of export templates returned by TC_Export_Handler::get_export_templates(). Each template is a keyed array describing how the export handler formats dates, numbers, and metadata when generating CSV, XLSX (OOXML), or PDF output. The plugin ships three built-in templates: default, business, and data_analysis.

ParameterTypeDescription
$templatesarrayAssociative array keyed by template slug. Each value is an array with name, description, include_metadata (bool), date_format (PHP date format), and number_format keys.

Add a custom template that includes metadata and uses a European date format:

add_filter( 'tc_export_templates', function( $templates ) {
    $templates['eu_report'] = [
        'name'             => 'EU Report',
        'description'      => 'European report format',
        'include_metadata' => true,
        'date_format'      => 'd/m/Y',
        'number_format'    => '0,00',
    ];
    return $templates;
} );

You can also override a built-in template by reusing its key (for example, changing the default template's date_format):

add_filter( 'tc_export_templates', function( $templates ) {
    $templates['default']['date_format'] = 'F j, Y'; // e.g. June 21, 2026
    return $templates;
} );

Keep date_format and number_format values consistent with PHP's date() and number formatting conventions so exported XLSX and PDF cells render predictably across tools.

tablecrafter_trusted_ip_headers

Filters the list of proxy header keys that TableCrafter's security layer is allowed to trust when resolving the client IP in TC_Security::get_client_ip(). This is used for rate limiting and security logging. For safety, the filter defaults to an empty array, meaning only REMOTE_ADDR is trusted unless you explicitly opt in.

ParameterTypeDescription
$trusted_headersarrayList of header keys to trust. Recognized keys map to known proxy headers: cloudflare (HTTP_CF_CONNECTING_IP), forwarded (HTTP_X_FORWARDED_FOR), and real_ip (HTTP_X_REAL_IP). Defaults to array().

Trust Cloudflare's connecting-IP header when your site sits behind Cloudflare:

add_filter( 'tablecrafter_trusted_ip_headers', function( $headers ) {
    $headers[] = 'cloudflare';
    return $headers;
} );
⚠️

Only enable a proxy header if your site is genuinely behind that proxy. Trusting a spoofable header (such as X-Forwarded-For) on a directly-exposed site lets clients forge their IP and bypass rate limiting. Even when a header is trusted, TableCrafter still validates the parsed value with FILTER_VALIDATE_IP and rejects private/reserved ranges.

Frontend JavaScript Events

On the client, the TableCrafter renderer emits native DOM CustomEvents for mobile card interactions. Every event name is prefixed with tablecrafter:, dispatched on the table's container element, and configured with bubbles: true so you can listen on a parent element or document.

EventFires whenevent.detail payload
tablecrafter:cardTapA user taps a card in the mobile card layout (expand/collapse).{ rowData, rowIndex, card }
tablecrafter:cardViewThe "view details" quick action is triggered on a card.{ rowData, rowIndex }
tablecrafter:cardEditThe "edit" quick action is triggered on a card.{ rowData, rowIndex }

The rowData property is the row's data object, rowIndex is its position in the dataset, and (for cardTap) card is the card DOM element. The built-in cardView and cardEdit handlers are deliberate placeholders so you can attach your own behavior.

Listen for card edits anywhere in the document and route them to your own UI:

document.addEventListener('tablecrafter:cardEdit', function (e) {
  const { rowData, rowIndex } = e.detail;
  // Open your custom edit modal with the row data
  openEditor(rowData, rowIndex);
});

document.addEventListener('tablecrafter:cardTap', function (e) {
  console.log('Card tapped at row', e.detail.rowIndex);
});
ℹ️

Because these events bubble, a single listener on document handles every table on the page. If you need to scope to one table, attach the listener to that table's container element instead.

Styling Hooks (CSS Custom Properties)

Beyond PHP and JS hooks, TableCrafter exposes CSS custom properties so you can theme tables without overriding the stylesheet. Set them on the table container or a parent scope:

PropertyControls
--tc-bg-colorTable/card background color.
--tc-text-colorPrimary text color.
--tc-border-colorCell and card border color.
--tc-focus-colorKeyboard focus outline color (accessibility).
.my-page .tablecrafter-container {
  --tc-bg-color: #0f172a;
  --tc-text-color: #e2e8f0;
  --tc-border-color: #334155;
  --tc-focus-color: #38bdf8;
}

What's Not a Hook

To avoid confusion, note the following about TableCrafter's extensibility model:

If you need behavior that no hook covers, prefer combining the frontend tablecrafter: events with shortcode attributes and CSS custom properties before patching the plugin — this keeps your customizations upgrade-safe.

Next Steps

To configure tables before reaching for code, see shortcode-reference.html for every [tablecrafter] attribute, and data-export.html to learn how the export templates filtered by tc_export_templates are applied to CSV, XLSX, and PDF output.