\ActionScheduler_ListTable

Implements the admin view of the actions.

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()
display_admin_notices()
process_actions()
display_page()
__construct()
set_items_per_page_option()
column_args()
column_log_entries()
column_schedule()
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_filter_by_status()
display_table()
get_search_box_placeholder()
get_per_page_option_name()
get_recurrence()
get_log_entry_html()
get_schedule_display_string()
row_action_cancel()
row_action_run()
recreate_tables()
process_row_action()
get_search_box_button_text()
$table_name
$package
$items_per_page
$search_by
$columns
$row_actions
$ID
$sort_by
$filter_by
$status_counts
$admin_notices
$table_header
$bulk_actions
$store
$logger
$runner
$did_notification
N/A
human_interval()
$time_periods
N/A

Properties

$table_name

$table_name : string

The table name

Type

normal

$package

$package : string

The package name.

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 (name => label).

Type

normal

$row_actions

$row_actions : array

Actions (name => label).

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

Bulk actions. The key of the array is the method name of the implementation.

Example: bulk_<key>(array $ids, string $sql_in).

See the comments in the parent class for further details

Type

normal

$store

$store : \ActionScheduler_Store

The active data stores

Type

normal

$logger

$logger : \ActionScheduler_Logger

A logger to use for getting action logs to display

Type

normal

$runner

$runner : \ActionScheduler_QueueRunner

A ActionScheduler_QueueRunner runner instance (or child class)

Type

normal

$did_notification

$did_notification : bool

Flag variable to render our notifications, if any, once.

Type

normal

$time_periods

$time_periods : array

Array of seconds for common time periods, like week or month, alongside an internationalised string representation, i.e. "Day" or "Days"

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

display_admin_notices()

display_admin_notices() : mixed

Renders admin notifications

Notifications:

  1. When the maximum number of tasks are being executed simultaneously.
  2. Notifications when a task is manually executed.
  3. Tables are missing.

Returns

mixed

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

__construct()

__construct(\ActionScheduler_Store  $store, \ActionScheduler_Logger  $logger, \ActionScheduler_QueueRunner  $runner) : mixed

Sets the current data store object into `store->action` and initialises the object.

Parameters

\ActionScheduler_Store $store

Store object.

\ActionScheduler_Logger $logger

Logger object.

\ActionScheduler_QueueRunner $runner

Runner object.

Returns

mixed

set_items_per_page_option()

set_items_per_page_option(mixed  $status, string  $option, int  $value) : int

Handles setting the items_per_page option for this screen.

Parameters

mixed $status

Default false (to skip saving the current option).

string $option

Screen option name.

int $value

Screen option value.

Returns

int

column_args()

column_args(array  $row) : string

Serializes the argument of an action to render it in a human friendly format.

Parameters

array $row

The array representation of the current row of the table.

Returns

string

column_log_entries()

column_log_entries(array  $row) : string

Prints the logs entries inline. We do so to avoid loading Javascript and other hacks to show it in a modal.

Parameters

array $row

Action array.

Returns

string

column_schedule()

column_schedule(array  $row) : string

Prints the scheduled date in a human friendly format.

Parameters

array $row

The array representation of the current row of the table.

Returns

string

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(int[]  $ids, string  $ids_sql) : void

Bulk delete.

Deletes actions based on their ID. This is the handler for the bulk delete. It assumes the data properly validated by the callee and it will delete the actions without any extra validation.

Parameters

int[] $ids

Action IDs.

string $ids_sql

Inherited and unused.

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

Only display row actions for pending 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 render.

string $column_name

Current row.

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_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

get_recurrence()

get_recurrence(\ActionScheduler_Action  $action) : string

Returns the recurrence of an action or 'Non-repeating'. The output is human readable.

Parameters

\ActionScheduler_Action $action

Action object.

Returns

string

get_log_entry_html()

get_log_entry_html(\ActionScheduler_LogEntry  $log_entry, \DateTimezone  $timezone) : string

Prints the logs entries inline. We do so to avoid loading Javascript and other hacks to show it in a modal.

Parameters

\ActionScheduler_LogEntry $log_entry

Log entry object.

\DateTimezone $timezone

Timestamp.

Returns

string

get_schedule_display_string()

get_schedule_display_string(\ActionScheduler_Schedule  $schedule) : string

Get the scheduled date in a human friendly format.

Parameters

\ActionScheduler_Schedule $schedule

Action's schedule.

Returns

string

row_action_cancel()

row_action_cancel(int  $action_id) : mixed

Implements the logic behind running an action. ActionScheduler_Abstract_ListTable validates the request and their parameters are valid.

Parameters

int $action_id

Action ID.

Returns

mixed

row_action_run()

row_action_run(int  $action_id) : mixed

Implements the logic behind running an action. ActionScheduler_Abstract_ListTable validates the request and their parameters are valid.

Parameters

int $action_id

Action ID.

Returns

mixed

recreate_tables()

recreate_tables() : mixed

Force the data store schema updates.

Returns

mixed

process_row_action()

process_row_action(int  $action_id, string  $row_action_type) : mixed

Implements the logic behind processing an action once an action link is clicked on the list table.

Parameters

int $action_id

Action ID.

string $row_action_type

The type of action to perform on the action.

Returns

mixed

get_search_box_button_text()

get_search_box_button_text() : mixed

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

Returns

mixed

human_interval()

human_interval(int  $interval, int  $periods_to_include = 2) : string

Convert an interval of seconds into a two part human friendly string.

The WordPress human_time_diff() function only calculates the time difference to one degree, meaning even if an action is 1 day and 11 hours away, it will display "1 day". This function goes one step further to display two degrees of accuracy.

Inspired by the Crontrol::interval() function by Edward Dale: https://wordpress.org/plugins/wp-crontrol/

Parameters

int $interval

A interval in seconds.

int $periods_to_include

Depth of time periods to include, e.g. for an interval of 70, and $periods_to_include of 2, both minutes and seconds would be included. With a value of 1, only minutes would be included.

Returns

string —

A human friendly string representation of the interval.