\ActionScheduler_Abstract_ListTable

Action Scheduler Abstract List Table class

This abstract class enhances WP_List_Table making it ready to use.

By extending this class we can focus on describing how our table looks like, which columns needs to be shown, filter, ordered by and more and forget about the details.

This class supports:

  • Bulk actions
  • Search
  • Sortable columns
  • Automatic translations of the columns

Summary

Methods
Properties
Constants
get_sortable_columns()
get_columns()
prepare_items()
extra_tablenav()
column_cb()
column_default()
process_actions()
display_page()
No public properties found
No constants found
translate()
get_bulk_actions()
process_bulk_action()
bulk_delete()
prepare_column_headers()
get_items_query_limit()
get_items_offset()
get_items_query_offset()
get_items_query_order()
get_request_query_args_to_persist()
get_request_orderby()
get_request_order()
get_request_status()
get_request_search_query()
get_table_columns()
get_items_query_search()
get_items_query_filters()
set_items()
maybe_render_actions()
process_row_actions()
display_header()
display_admin_notices()
display_filter_by_status()
display_table()
get_search_box_placeholder()
get_per_page_option_name()
$table_name
$package
$items_per_page
$search_by
$columns
$row_actions
$ID
$sort_by
$filter_by
$status_counts
$admin_notices
$table_header
$bulk_actions
N/A
No private methods found
No private properties found
N/A

Properties

$table_name

$table_name : string

The table name

Type

normal

$package

$package : string

Package name, used to get options from WP_List_Table::get_items_per_page.

Type

normal

$items_per_page

$items_per_page : int

How many items do we render per page?

Type

normal

$search_by

$search_by : array

Enables search in this table listing. If this array is empty it means the listing is not searchable.

Type

normal

$columns

$columns : array

Columns to show in the table listing. It is a key => value pair. The key must much the table column name and the value is the label, which is automatically translated.

Type

normal

$row_actions

$row_actions : array

Defines the row-actions. It expects an array where the key is the column name and the value is an array of actions.

The array of actions are key => value, where key is the method name (with the prefix rowaction<key>) and the value is the label and title.

Type

normal

$ID

$ID : string

The Primary key of our table

Type

normal

$sort_by

$sort_by : array

Enables sorting, it expects an array of columns (the column names are the values)

Type

normal

$filter_by

$filter_by : string

The default sort order

Type

normal

$status_counts

$status_counts : array

The status name => count combinations for this table's items. Used to display status filters.

Type

normal

$admin_notices

$admin_notices : array

Notices to display when loading the table. Array of arrays of form array( 'class' => {updated|error}, 'message' => 'This is the notice text display.' ).

Type

normal

$table_header

$table_header : string

Localised string displayed in the <h1> element above the able.

Type

normal

$bulk_actions

$bulk_actions : array

Enables bulk actions. It must be an array where the key is the action name and the value is the label (which is translated automatically). It is important to notice that it will check that the method exists (`bulk_$name`) and will throw an exception if it does not exists.

This class will automatically check if the current request has a bulk action, will do the validations and afterwards will execute the bulk method, with two arguments. The first argument is the array with primary keys, the second argument is a string with a list of the primary keys, escaped and ready to use (with IN).

Type

normal

Methods

get_sortable_columns()

get_sortable_columns() : mixed

Reads $this->sort_by and returns the columns name in a format that WP_Table_List expects

Returns

mixed

get_columns()

get_columns() : mixed

Returns the columns names for rendering. It adds a checkbox for selecting everything as the first column

Returns

mixed

prepare_items()

prepare_items() : mixed

Prepares the data to feed WP_Table_List.

This has the core for selecting, sorting and filtering data. To keep the code simple its logic is split among many methods (get_itemsquery*).

Beside populating the items this function will also count all the records that matches the filtering criteria and will do fill the pagination variables.

Returns

mixed

extra_tablenav()

extra_tablenav(string  $which) : mixed

Display the table.

Parameters

string $which

The name of the table.

Returns

mixed

column_cb()

column_cb(array  $row) : mixed

Renders the checkbox for each row, this is the first column and it is named ID regardless of how the primary key is named (to keep the code simpler). The bulk actions will do the proper name transformation though using `$this->ID`.

Parameters

array $row

The row to render.

Returns

mixed

column_default()

column_default(array  $item, string  $column_name) : string

Default column formatting, it will escape everything for security.

Parameters

array $item

The item array.

string $column_name

Column name to display.

Returns

string

process_actions()

process_actions() : mixed

Process any pending actions.

Returns

mixed

display_page()

display_page() : mixed

Render the list table page, including header, notices, status filters and table.

Returns

mixed

translate()

translate(string  $text, string  $context = '') : string|void

Makes translation easier, it basically just wraps `_x` with some default (the package name).

Parameters

string $text

The new text to translate.

string $context

The context of the text.

Returns

string|void —

The translated text.

get_bulk_actions()

get_bulk_actions() : array

Reads `$this->bulk_actions` and returns an array that WP_List_Table understands. It also validates that the bulk method handler exists. It throws an exception because this is a library meant for developers and missing a bulk method is a development-time error.

Throws

\RuntimeException

Throws RuntimeException when the bulk action does not have a callback method.

Returns

array

process_bulk_action()

process_bulk_action() : mixed

Checks if the current request has a bulk action. If that is the case it will validate and will execute the bulk method handler. Regardless if the action is valid or not it will redirect to the previous page removing the current arguments that makes this request a bulk action.

Returns

mixed

bulk_delete()

bulk_delete(array  $ids, string  $ids_sql) : void

Default code for deleting entries.

validated already by process_bulk_action()

Parameters

array $ids

ids of the items to delete.

string $ids_sql

the sql for the ids.

prepare_column_headers()

prepare_column_headers() : mixed

Prepares the _column_headers property which is used by WP_Table_List at rendering.

It merges the columns and the sortable columns.

Returns

mixed

get_items_query_limit()

get_items_query_limit() : string

Get prepared LIMIT clause for items query

Returns

string —

Prepared LIMIT clause for items query.

get_items_offset()

get_items_offset() : int

Returns the number of items to offset/skip for this current view.

Returns

int

get_items_query_offset()

get_items_query_offset() : string

Get prepared OFFSET clause for items query

Returns

string —

Prepared OFFSET clause for items query.

get_items_query_order()

get_items_query_order() : mixed

Prepares the ORDER BY sql statement. It uses `$this->sort_by` to know which columns are sortable. This requests validates the orderby $_GET parameter is a valid column and sortable. It will also use order (ASC|DESC) using DESC by default.

Returns

mixed

get_request_query_args_to_persist()

get_request_query_args_to_persist() : string[]

Querystring arguments to persist between form submissions.

Returns

string[]

get_request_orderby()

get_request_orderby() : string

Return the sortable column specified for this request to order the results by, if any.

Returns

string

get_request_order()

get_request_order() : string

Return the sortable column order specified for this request.

Returns

string

get_request_status()

get_request_status() : string

Return the status filter for this request, if any.

Returns

string

get_request_search_query()

get_request_search_query() : string

Return the search filter for this request, if any.

Returns

string

get_table_columns()

get_table_columns() : array

Process and return the columns name. This is meant for using with SQL, this means it always includes the primary key.

Returns

array

get_items_query_search()

get_items_query_search() : string

Check if the current request is doing a "full text" search. If that is the case prepares the SQL to search texts using LIKE.

If the current request does not have any search or if this list table does not support that feature it will return an empty string.

Returns

string

get_items_query_filters()

get_items_query_filters() : mixed

Prepares the SQL to filter rows by the options defined at `$this->filter_by`. Before trusting any data sent by the user it validates that it is a valid option.

Returns

mixed

set_items()

set_items(array  $items) : mixed

Set the data for displaying. It will attempt to unserialize (There is a chance that some columns are serialized). This can be override in child classes for further data transformation.

Parameters

array $items

Items array.

Returns

mixed

maybe_render_actions()

maybe_render_actions(array  $row, string  $column_name) : string

Renders the row-actions.

This method renders the action menu, it reads the definition from the $row_actions property, and it checks that the row action method exists before rendering it.

Parameters

array $row

Row to be rendered.

string $column_name

Column name.

Returns

string

process_row_actions()

process_row_actions() : void

Process the bulk actions.

display_header()

display_header() : mixed

Display the table heading and search query, if any

Returns

mixed

display_admin_notices()

display_admin_notices() : mixed

Display the table heading and search query, if any

Returns

mixed

display_filter_by_status()

display_filter_by_status() : mixed

Prints the available statuses so the user can click to filter.

Returns

mixed

display_table()

display_table() : mixed

Renders the table list, we override the original class to render the table inside a form and to render any needed HTML (like the search box). By doing so the callee of a function can simple forget about any extra HTML.

Returns

mixed

get_search_box_placeholder()

get_search_box_placeholder() : mixed

Get the text to display in the search box on the list table.

Returns

mixed

get_per_page_option_name()

get_per_page_option_name() : string

Gets the screen per_page option name.

Returns

string