Ga naar inhoud

Entry list table hooks

Deze inhoud is nog niet vertaald.

The Entries and Payments admin pages show a list table with one row per entry. With the hooks on this page you can add columns, change the labels and content of existing columns, add bulk actions and widen the search.

Cell content is escaped as text before a column filter runs, and the filter result may contain safe HTML (wp_kses_post()). That way stored values can never inject markup, but your filter can still add some.

Core uses these column names: cb, post_name (the ID column), post_title, type, source, client, status and post_date. The columns post_name, type, source, client and status have a dedicated filter. All other columns, including your own, go through the cs_entry_list_column_{column_name} and cs_entry_list_column filters.

Filter · admin/entry/class-list-table.php

Filters the meta keys the list table’s search box searches in. The search term is matched with LIKE against each key, and an entry matches if any key matches.

Parameter Type Description
$fields string[] The meta keys. Default: client, source_id and source.

Returns: string[] — the meta keys to search.

add_filter('cs_entry_search_fields', function ($fields) {
$fields[] = 'my_addon_reference';
return $fields;
});

Filter · admin/entry/class-list-table.php

Filters the columns of the list table.

Parameter Type Description
$columns array<string, string> The column titles keyed by column name. Default: cb, post_name (ID), post_title, type, source, client, status and post_date.
$table List_Table The list table object. Use $table->get_type() for the entry type that is shown (all, entry, payment or a custom type).

Returns: array<string, string> — the column titles keyed by column name.

add_filter('cs_entry_list_columns', function ($columns, $table) {
$columns['campaign'] = __('Campaign', 'my-addon');
return $columns;
}, 10, 2);

Filter · admin/entry/class-list-table.php

Filters the columns that can be sorted.

Parameter Type Description
$columns array<string, array> The sortable columns keyed by column name, each as [orderby, initially_descending]. Default: post_date as ['post_date', true] and post_name as ['ID', true].
$table List_Table The list table object.

Returns: array<string, array> — the sortable columns keyed by column name.

add_filter('cs_entry_list_sortable_columns', function ($columns, $table) {
$columns['post_title'] = ['post_title', false];
return $columns;
}, 10, 2);

Filter · admin/entry/class-list-table.php

Filters the bulk actions of the list table. By default the trash view has untrash (Recover) and delete (Delete permanently), and the other views have trash (Put in trash). Handle your own action with cs_entry_list_bulk_action_{action}.

Parameter Type Description
$actions array<string, string> The action labels keyed by action name.
$table List_Table The list table object.

Returns: array<string, string> — the action labels keyed by action name.

add_filter('cs_entry_list_bulk_actions', function ($actions, $table) {
$actions['resend'] = __('Send again', 'my-addon');
return $actions;
}, 10, 2);

Action · admin/entry/class-list-table.php

Fires when a bulk action that Core does not handle itself is submitted. The dynamic part {action} is the action name that you added with cs_entry_list_bulk_actions. The built-in actions trash, untrash and delete don’t fire it. Only entries the current user may delete are passed, and the nonce has already been checked. After the action runs, Core redirects back to the list.

Parameter Type Description
$entries int[] The IDs of the selected entries.
$table List_Table The list table object.
add_action('cs_entry_list_bulk_action_resend', function ($entries, $table) {
foreach ($entries as $entry_id) {
$entry = cs_get_entry($entry_id);
if ($entry) {
$entry->execute();
}
}
}, 10, 2);

Filter · admin/entry/class-list-table.php

Filters the message that is shown when the list is empty. It only runs for list tables of a custom entry type, because all, entry and payment have a fixed message (“No entries found.” and “No payments found.”). The message may contain safe HTML.

Parameter Type Description
$message string The message. Default: No items found.
$type string The entry type of the list table.
$table List_Table The list table object.

Returns: string — the message.

add_filter('cs_entry_list_no_items_message', function ($message, $type, $table) {
return $type === 'donation' ? __('No donations yet.', 'my-addon') : $message;
}, 10, 3);

Filter · admin/entry/class-list-table.php

Filters the labels shown in the Type column. A type without a label is shown as is.

Parameter Type Description
$labels array<string, string> The labels keyed by entry type. Default: entry (Entry) and payment (Payment).

Returns: array<string, string> — the labels keyed by entry type.

add_filter('cs_entry_list_column_type_labels', function ($labels) {
$labels['donation'] = __('Donation', 'my-addon');
return $labels;
});

Filter · admin/entry/class-list-table.php

Filters the content of the Type column.

Parameter Type Description
$value string The escaped label of the type.
$type string The raw entry type.
$item WP_Post The entry post of the row.

Returns: string — the cell content; safe HTML is allowed.

add_filter('cs_entry_list_column_type', function ($value, $type, $item) {
return $type === 'donation' ? '<strong>' . $value . '</strong>' : $value;
}, 10, 3);

Filter · admin/entry/class-list-table.php

Filters the data that builds the ID column (post_name), which shows the entry ID and, when available, the source label and the source ID. Change source_label, source_id or source_link to change how the source is shown.

Parameter Type Description
$data array id (the entry post ID), source, source_label (empty by default), source_id, source_link and edit_link.
$item WP_Post The entry post of the row.

Returns: array — the data, with the same keys.

add_filter('cs_entry_list_column_name_data', function ($data, $item) {
if ($data['source'] === 'my-form') {
$data['source_label'] = __('My form', 'my-addon');
}
return $data;
}, 10, 2);

Filter · admin/entry/class-list-table.php

Filters the finished markup of the ID column (post_name). Only the tags a (with href and target), strong and small survive.

Parameter Type Description
$value string The column markup.
$item WP_Post The entry post of the row.
$data array The data from cs_entry_list_column_name_data.

Returns: string — the column markup.

add_filter('cs_entry_list_column_name', function ($value, $item, $data) {
return $value . ' <small>' . esc_html($data['source']) . '</small>';
}, 10, 3);

Filter · admin/entry/class-list-table.php

Filters the labels of the entry sources, which appear in the Source column and as the source label in the ID column. A source without a label is shown as is.

Parameter Type Description
$labels array<string, string> The labels keyed by source. Default: campaignsuite (CampaignSuite).

Returns: array<string, string> — the labels keyed by source.

add_filter('cs_entry_list_column_source_labels', function ($labels) {
$labels['my-form'] = __('My form', 'my-addon');
return $labels;
});

Filter · admin/entry/class-list-table.php

Filters the content of the Source column.

Parameter Type Description
$value string The escaped source label.
$source string The raw source stored on the entry.
$item WP_Post The entry post of the row.

Returns: string — the cell content; safe HTML is allowed.

add_filter('cs_entry_list_column_source', function ($value, $source, $item) {
return $source === 'my-form' ? '<em>' . $value . '</em>' : $value;
}, 10, 3);

Filter · admin/entry/class-list-table.php

Filters the labels of the entry clients, shown in the Client column. A client without a label is shown as is.

Parameter Type Description
$labels array<string, string> The labels keyed by client. Default: campaignsuite (CampaignSuite), salesforce (Salesforce) and dynamics (Dynamics).

Returns: array<string, string> — the labels keyed by client.

add_filter('cs_entry_list_column_client_labels', function ($labels) {
$labels['my-crm'] = __('My CRM', 'my-addon');
return $labels;
});

Filter · admin/entry/class-list-table.php

Filters the content of the Client column.

Parameter Type Description
$value string The escaped client label.
$client string The raw client stored on the entry.
$item WP_Post The entry post of the row.

Returns: string — the cell content; safe HTML is allowed.

add_filter('cs_entry_list_column_client', function ($value, $client, $item) {
return $value;
}, 10, 3);

Filter · admin/entry/class-list-table.php

Filters the content of the Status column. The label comes from the entry class of the row, so an entry class from another plugin can provide its own status labels.

Parameter Type Description
$value string The escaped, translated status label.
$item WP_Post The entry post of the row.

Returns: string — the cell content; safe HTML is allowed.

add_filter('cs_entry_list_column_status', function ($value, $item) {
return '<span class="my-status">' . $value . '</span>';
}, 10, 2);

Filter · admin/entry/class-list-table.php

Filters the content of a column that has no dedicated filter. The dynamic part {column_name} is the column name from cs_entry_list_columns. Known concrete values are post_title and post_date, plus every column that you add yourself. By default the value is the entry post property with the same name, so a custom column stays empty until a filter provides content.

Parameter Type Description
$value string The escaped property value, or an empty string.
$item WP_Post The entry post of the row.

Returns: string — the cell content; safe HTML is allowed.

add_filter('cs_entry_list_column_campaign', function ($value, $item) {
return esc_html(get_post_meta($item->ID, 'my_addon_campaign', true));
}, 10, 2);

Filter · admin/entry/class-list-table.php

Filters the content of every column rendered by the default column handler, which are the same columns as for cs_entry_list_column_{column_name}. It runs after that filter.

Parameter Type Description
$value string The cell content after cs_entry_list_column_{column_name}.
$column_name string The column name.
$item WP_Post The entry post of the row.

Returns: string — the cell content; safe HTML is allowed.

add_filter('cs_entry_list_column', function ($value, $column_name, $item) {
return $column_name === 'post_date' ? esc_html(human_time_diff(strtotime($item->post_date))) : $value;
}, 10, 3);