Class WPDA_List_Table_Menu

This class implements the Data Explorer shown in the plugin menu.

WPDA_List_Table_Menu extends WPDA_List_Table. Although both list tables basically offer the same functionality WPDA_List_Table_Menu selects data from MySQL view 'information_schema.tables', where WPDA_List_Table selects data from tables that are located in the WordPress database schema. The view that serves as the 'base table' for WPDA_List_Table_Menu is not updatable. A data entry form is therefor not available for WPDA_List_Table_Menu.

Export functionality word WPDA_List_Table_Menu differs from WPDA_List_Table as well. WPDA_List_Table_Menu allows to export single tables, as well as multiple tables at once as s bulk action.

When the user clicks on 'view', a list table for the selected table of view is shown.

author Peter Schulz
since 1.0.0
package WPDataAccess\List_Table
inherited_from \WPDataAccess\List_Table\WPDA_List_Table

 Methods

WPDA_List_Table_Menu constructor

__construct(array $args = array()

Constructor calls constructor of WPDA_List_Table. Before calling constructor of WPDA_List_Table the table name is set to \WPDataAccess\List_Table\WPDA_List_Table::LIST_BASE_TABLE which gives us the base table for the data explorer.

Column headers and columns queried are defined harcoded as this class handles only one base table and it's columns (table specific implementation).

see \WPDataAccess\List_Table\WPDA_List_Table
since 1.0.0
inherited_from \WPDataAccess\List_Table\WPDA_List_Table::__construct()

Parameters

$args

array

See {@see WPDA_List_Table::__construct()}.

WPDA_List_Table constructor

__construct(array $args = array()
Inherited

A table name must be provided in the constructor call. The table must be a valid MySQL database table to which acces (to the back-end) is granted. If no table name is provided, the table does not exist or access to the back-end for the given table is not granted, processing is stopped. It makes no sense to continue without a valid table. A check for table existence is performed to prevent SQL injection.

There are two types of tables to build a list table on:

  • List of tables in the WordPress database schema
  • List of rows in a specific table

To build a list of tables in the WordPress database schema, we query table 'information_schema.tables' (which is in fact a view). This is the only query allowed outside the WordPress database schema. The table/view name is stored in constant WPDA_List_Table::LIST_BASE_TABLE for validation purposes.

A list of rows for a specific table is based on WordPress class WP_List_Table.

WPDA_List_Table can be used to build list tables for views as well. View based list tables however, do not support insert, update, delete, import and export actions.

A table name is not the only thing we need to build a list table. We also need to have access to the table columns. If no table columns are provided execution is stopped as well.

since 1.0.0

Parameters

$args

array

[

'table_name' => (string) Database table name

'wpda_list_columns' => (object) Reference to a WPDA_List_Columns object

'singular' => (string) Singular object label

'plural' => (string) lural object label

'ajax' => (string) TRUE = list table support Ajax

'column_headers' => (array|string) Column headers

'title' => (string) Page title

'subtitle' => (string) Page subtitle

'bulk_export_enabled' => (boolean)

'search_box_enabled' => (boolean)

'bulk_actions_enabled' => (boolean)

'show_view_link' => (string) on|off

'allow_insert' => (string) on|off

'allow_update' => (string) on|off

'allow_delete' => (string) on|off

'allow_import' => (string) on|off

'hide_navigation' => (boolean)

'default_where' => (string)

]

Override column_cb

column_cb(array $item) : string
since 1.0.0
see \WPDataAccess\List_Table\WPDA_List_Table::column_cb()
inherited_from \WPDataAccess\List_Table\WPDA_List_Table::column_cb()

Parameters

$item

array

Column info.

Returns

string

Render bulk edit checkbox

column_cb(array $item) : string
Inherited
since 1.0.0

Parameters

$item

array

Column list.

Returns

stringContent for checkbox column.

Override column_default

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

We need to override this method as our table is in fact a view and has no real columns: $this->wpda_list_columns->get_table_columns() returns no results

We'll use jquery to write html forms to a container to make them accessible inside our list table. See WPDA_List_Table->column_default for further explanation.

see \WPDataAccess\List_Table\WPDA_List_Table::column_default()
since 1.0.0
inherited_from \WPDataAccess\List_Table\WPDA_List_Table::column_default()

Parameters

$item

array

Item info.

$column_name

string

Column name.

Returns

mixedActions for the current row.

Render columns

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

Three links are provided for every list table row:

  • 'View' => Link to view form (readonly data entry form)
  • 'Edit' => Link to data entry form (updatable)
  • 'Delete' => Link to delete record from database table

Links to view, edit and delete records are only available if a primary key for the table is found. Without a primary key unique identification of records is not possible.

Links to action are offered through hidden forms to prevent long URL's and problem when refreshing pages manually. More information about how and why is provided in source code at place where I thoug the information could be helpful.

since 1.0.0

Parameters

$item

array

Column info.

$column_name

string

Column name.

Returns

mixedValue display in list table column

Add labels to static function to make it available to class WPDA_List _View. Allowing to hide columns in Data Explorer main page.

column_headers_labels() : array
Static
since 2.0.3

Returns

array

column_media_attachment()

column_media_attachment($url, $title, $mime_type) 
InheritedStatic

Parameters

$url

$title

$mime_type

Delete record from database table

delete_row(string $where) : mixed
Inherited

The table must have a primary key and the values for all primary key colummns must be provided in the request. The where clause must be a named array in format: ['column_name'] = 'value'

since 1.0.0

Parameters

$where

string

Where clause.

Returns

mixed

Override get_bulk_actions

get_bulk_actions() : array
see \WPDataAccess\List_Table\WPDA_List_Table::get_bulk_actions()
since 1.0.0
inherited_from \WPDataAccess\List_Table\WPDA_List_Table::get_bulk_actions()

Returns

array

Returns an associative array containing the bulk action

get_bulk_actions() : array
Inherited
since 1.0.0

Returns

array

Override get_columns

get_columns() : array
see \WPDataAccess\List_Table\WPDA_List_Table::get_columns()
since 1.0.0
inherited_from \WPDataAccess\List_Table\WPDA_List_Table::get_columns()

Returns

array

Return an associative array of columns

get_columns() : array
Inherited
since 1.0.0

Returns

array

Perform query to retrieve rows from database

get_rows() 
Inherited

Where clause must be prepared in advance and written to $this->where (\WPDataAccess\List_Table\WPDA_List_Table::construct_where_clause()).

No return value. Result is directly written to $this->items (base class member).

since 1.0.0

Override get_sortable_columns()

get_sortable_columns() : array

Type is not sortable as it is not in the view.

see \WPDataAccess\List_Table\WPDA_List_Table::get_sortable_columns()
since 1.0.0
inherited_from \WPDataAccess\List_Table\WPDA_List_Table::get_sortable_columns()

Returns

array

List of columns to make sortable

get_sortable_columns() : array
Inherited
since 1.0.0

Returns

array

get_where_clause()

get_where_clause() 
Inherited

I18n text displayed when no data found

no_items() 
Inherited
since 1.0.0

Prepares the list of items for displaying

prepare_items() 
Inherited

Overwrites WP_List_Table::prepare_items()

since 1.0.0

Print column headers

print_column_headers(boolean $with_id = true
Inherited

Overriding original method print_column_headers to support post instead of get. Changes are marked!

since 1.0.0
staticvar $cb_counter int

Parameters

$with_id

boolean

Whether to set the id attribute or not.

Override process_bulk_action()

process_bulk_action() 

Delete and bulk-delete actions use the primary key list as a reference. Before performing the actual delete statement(s) we'll check the provided column names against the data dictionary. This will protect us against SQL injection attacks.

For export actions table names will not be checked here. They are handed over WPDA_Export where the validity and access rights are checked anyway (to be safe).

All actions can be processed only with a valid wpnonce value.

To perform actions the user must have the appropriate rights.

since 1.0.0
see \WPDataAccess\List_Table\WPDA_List_Table::process_bulk_action()
inherited_from \WPDataAccess\List_Table\WPDA_List_Table::process_bulk_action()

Process bulk actions

process_bulk_action() 
Inherited

Delete and bulk-delete actions use the primary key list as a reference. Before performing the actual delete statement(s) we'll check the provided column names against the data dictionary. This will protect us against SQL injection attacks.

For export actions table names will not be checked here. They are handed over WPDA_Export where the validity and access rights are checked anyway (to be safe).

All actions can be processed only with a valid wpnonce value.

To perform actions the user must have the appropriate rights.

since 1.0.0

Number of records in database table

record_count() : null | string
Inherited

Returns the number of records in the database table. Where clause must be prepared in advance and written to $this->where (\WPDataAccess\List_Table\WPDA_List_Table::construct_where_clause())

since 1.0.0

Returns

nullstringNumber of rows in the current table

Enable or disable bulk actions

set_bulk_actions_enabled(boolean $bulk_actions_enabled) 
Inherited
since 1.0.0

Parameters

$bulk_actions_enabled

boolean

TRUE = allowed, FALSE = not allowed.

Enable or disable bulk export options

set_bulk_export_enabled(boolean $bulk_export_enabled) 
Inherited
since 1.0.0

Parameters

$bulk_export_enabled

boolean

TRUE = allowed, FALSE = not allowed.

Set columns to be queries

set_columns_queried(mixed $columns_queried) 
Inherited

Set columns to be queried and shown in the list table. By default all columns in the table will be displayed.

since 1.0.0

Parameters

$columns_queried

mixed

Column list.

Show or hide search box

set_search_box_enabled(boolean $search_box_enabled) 
Inherited
since 1.0.0

Parameters

$search_box_enabled

boolean

TRUE = show search box, FALSE = do not show search bow.

Set page subtitle

set_subtitle(string $subtitle) 
Inherited
since 1.0.0

Parameters

$subtitle

string

Page subtitle.

Set page title

set_title(string $title) 
Inherited
since 1.0.0

Parameters

$title

string

Page title.

Overwrite method: add bulk array to check ddl allowed

show() 

Inside the list table page, the list table is shown. The necessary functionality to show the list table specifically is found in method \WPDataAccess\List_Table\WPDA_List_Table::display().

inherited_from \WPDataAccess\List_Table\WPDA_List_Table::show()

Show list table page

show() 
Inherited

Inside the list table page, the list table is shown. The necessary functionality to show the list table specifically is found in method \WPDataAccess\List_Table\WPDA_List_Table::display().

since 1.0.0
see \WPDataAccess\List_Table\WPDA_List_Table::display()

Overwrite method to add structure to the row below.

single_row(object $item) 
since 1.5.0

Parameters

$item

object

Iten info.

Add container to create new database

add_db_containers() 

Overwrite method: add button to design a table

add_header_button(string $add_param = ''

By default "add new" and "import" buttons are added (depending on the settings). Overwrite this method to add your own buttons.

inherited_from \WPDataAccess\List_Table\WPDA_List_Table::add_header_button()

Parameters

$add_param

string

Add button to page header

add_header_button(string $add_param = ''
Inherited

By default "add new" and "import" buttons are added (depending on the settings). Overwrite this method to add your own buttons.

since 1.0.1

Parameters

$add_param

string

Parameter to be added to form action.

Use this method to build parent child relationships.

add_parent_args_as_string(array $item) : string
Inherited

Overwrite this function if you want to use the list table as a child list table related to some parent form. You can add parent arguments to calls to make sure you get back to the right parent.

since 1.5.0

Parameters

$item

array

Column info.

Returns

stringString contains parent arguments.

Bind javascript code to action buttons

bind_action_buttons() 
Inherited
since 1.6.2

Override this method to add actions to first column of row

column_default_add_action(array $item, string $column_name, array $actions) 
Inherited

Parameters

$item

array

Item information.

$column_name

string

Column name.

$actions

array

Array of actions to be added to row.

Overwrite construct_where_clause()

construct_where_clause() 

Arguments might come from the URL so we need to check for SQL injection and use prepare. The resulting where clause is written directly to member $this->where.

since 1.0.0
see \WPDataAccess\List_Table\WPDA_List_Table::construct_where_clause()
inherited_from \WPDataAccess\List_Table\WPDA_List_Table::construct_where_clause()

Build where clause

construct_where_clause() 
Inherited

Arguments might come from the URL so we need to check for SQL injection and use prepare. The resulting where clause is written directly to member $this->where.

since 1.0.0

Copy table.

copy_table(string $copy_table_name_src, string $copy_table_name_dst, string $include_data) : false | integer
since 1.6.6

Parameters

$copy_table_name_src

string

Source table name.

$copy_table_name_dst

string

Destination table name.

$include_data

string

'on' = include data.

Returns

falseinteger

Count the number of rows in a table.

count_rows(string $table_name) : integer | null

This method is used to get the number of rows in an InnoDB table as the table_rows column of information_schema.tables only return an estimate.

since 1.5.1

Parameters

$table_name

string

Database table name.

Returns

integernullNumber of rows in $table_name.

Generates the table navigation

display_tablenav(string $which) : void
Inherited

Generates the table navigation above or bellow the table and removes the _wp_http_referrer and _wpnonce because it generates a error about URL too large.

since 1.0.0

Parameters

$which

string

CSS Class name.

Performs drop table.

drop_table(string $table_name) : boolean
since 1.5.0

Parameters

$table_name

string

Database table name.

Returns

booleanTRUE = table dropped.

Performs drop view.

drop_view(string $view_name) : boolean
since 1.5.0

Parameters

$view_name

string

Database view name.

Returns

booleanTRUE = view dropped.

Get database object type (VIEW, BASE_TABLE, SYSTEM VIEW).

get_dbo_type(string $dbo_name) : string | boolean
since 1.5.0

Parameters

$dbo_name

string

Table or view name.

Returns

stringbooleanDatabase object type or false.

Get favourite selection from cookie or list

get_favourites() : null | string
since 1.6.0

Returns

nullstring

Generate hidden fields for keys

get_key_input_fields(array $item) : string
Inherited

Parameters

$item

array

Column info.

Returns

stringString containg key items and values.

Get schema name from cookie or list

get_schema_name() : null | string
since 1.6.0

Returns

nullstring

Get search value (entered by the user or taken from cookie).

get_search_value() : string
Inherited
since 1.5.0

Returns

string

Overwrite method to prevent double row actions

handle_row_actions(object $item, string $column_name, string $primary) : string
Inherited

Parameters

$item

object

$column_name

string

$primary

string

Returns

string

Display the pagination

pagination(string $which) 
Inherited

Overriding original method pagination to support post instead of get. Changes are marked!

since 1.0.0

Parameters

$which

string

CSS Class name.

Silently delete table related info from repository (called after drop table)

post_drop_table(string $drop_table_name) 

Parameters

$drop_table_name

string

Database table name

Performs a drop table or view

process_bulk_action_bulk_drop() 

Method does not drop WordPress tables.

Performs bulk export.

process_bulk_action_bulk_export() 
since 1.5.0

Performs a truncate table

process_bulk_action_bulk_truncate() 

Method does not truncate WordPress tables.

Checks request argument needed for (bulk) action to be performed.

process_bulk_action_check_action(string $argument_name, string $msg) : boolean
since 1.5.0

Parameters

$argument_name

string

Request argument name.

$msg

string

Message on failure.

Returns

booleanTRUE = argument found in request.

Checks if table is a WordPress table.

process_bulk_action_check_is_wp_table(string $table_name, string $err_txt = '') : boolean
since 1.5.0

Parameters

$table_name

string

Database table name.

$err_txt

string

Additional error text/info.

Returns

booleanTRUE = table is WordPress table.

Checks if table exists.

process_bulk_action_check_table_exists(string $table_name, string $err_txt = '') : boolean
since 1.5.0

Parameters

$table_name

string

Database table name.

$err_txt

string

Additional error text/info.

Returns

booleanTRUE = table exists.

Checks wpnonce against a specific action.

process_bulk_action_check_wpnonce(string $wp_nonce_action, string $wp_nonce_arg) : boolean
since 1.5.0

Parameters

$wp_nonce_action

string

Nonce action.

$wp_nonce_arg

string

Nonce argument.

Returns

booleanTRUE = action allowed.

Performs copying a table.

process_bulk_action_copy_table() 
since 1.6.6

process_bulk_action_create_db()

process_bulk_action_create_db() 

process_bulk_action_delete_menu()

process_bulk_action_delete_menu() 

Processes drop table request.

process_bulk_action_drop() 
since 1.5.0

process_bulk_action_drop_db()

process_bulk_action_drop_db() 

process_bulk_action_edit_db()

process_bulk_action_edit_db() 

Performs optimize table.

process_bulk_action_optimize_table() 

Performs rename table/view.

process_bulk_action_rename_table() 
since 1.6.6

Save table settings.

process_bulk_action_settings_table() 

Processes truncate table request.

process_bulk_action_truncate() 
since 1.5.0

Rename table/view.

rename_table(string $rename_table_name_old, string $rename_table_name_new) : false | integer
since 1.6.6

Parameters

$rename_table_name_old

string

Old table name.

$rename_table_name_new

string

New table name.

Returns

falseinteger

Render column content

render_column_content(string $column_content, string $column_name) : string
Inherited

Strip content if too long and replace & character.

Parameters

$column_content

string

Unprepared column content

$column_name

string

Database column name

Returns

stringRendered column content

Performs truncate table.

truncate_table(string $table_name) : boolean
since 1.5.0

Parameters

$table_name

string

Database table name.

Returns

booleanTRUE = table truncated.

 Properties

 

Allow deletes?

$allow_delete : string

Default

null
 

Allow inserts?

$allow_insert : string

Default

null
 

Allow updates?

$allow_update : string

Default

null
 

Enable bulk actions?

$bulk_actions_enabled : boolean

Default

\WPDataAccess\List_Table\WPDA_List_Table::DEFAULT_BULK_ACTIONS_ENABLED
 

Enable exports?

$bulk_export_enabled : boolean

Default

\WPDataAccess\List_Table\WPDA_List_Table::DEFAULT_BULK_EXPORT_ENABLED
 

Child tab clicked (used for parent child relationships only)

$child_tab : null

Default

''
 

Column headers (labels)

$column_headers : array

Default

 

Store columns in array with column name as index for fast access

$columns_indexed : array

Default

array()
 

Columns in query

$columns_queried : array

Default

 

Page number

$current_page : integer

Default

1
 

Holds tables marked as favourite

$favourites : array | null

Default

null
 

Name of the column containing action links

$first_display_column : string

Default

''

Default is the first column displayed

 

Show help icon if hrlp url is available

$help_url : null | string

Default

null
 

Hides tablenav

$hide_navigation : boolean

Default

false
 

Indicates whether innodb_file_per_table is enabled or disabled

$innodb_file_per_table : boolean

Default

true
 

Number of rows displayed in list box

$items_per_page : integer

Default

 

Table row number within the current response

$list_number : integer

Default

0
Static
 

Menu slug of the current page

$page : string

Default

 

Page number text item

$page_number_item : null

Default

''
 

Page number item name (default 'page_number')

$page_number_item_name : string

Default

'page_number'

The name can be changed for pages on multiple levels. This is needed to get back to the right page in parent-child page.

   

Database schema name

$schema_name : string

Default

''
 

Add search box?

$search_box_enabled : boolean

Default

\WPDataAccess\List_Table\WPDA_List_Table::DEFAULT_SEARCH_BOX_ENABLED
 

Name of search item (WP default 's')

$search_item_name : string

Default

SELF::SEARCH_ITEM_NAME_DEFAULT
 

Search string (entered by user or taken from cookie)

$search_value : null | string

Default

null
 

Previous search string

$search_value_old : null | string

Default

null
 

$show_page_title

$show_page_title 

Default

true
   

Page subtitle

$subtitle : string

Default

''
 

Used to switch to another schema (after create/drop db)

$switch_schema_name : null

Default

null
 

Database table name

$table_name : string

Default

''
 

Page title

$title : string

Default

 

Can user create database

$user_can_create_db : boolean

Default

false
 

Can user drop database

$user_can_drop_db : boolean

Default

false
 

Hint button create db

$user_create_db_hint : string

Default

''
 

Hint button drop db

$user_drop_db_hint : string

Default

''
 

Where clause

$where : string

Default

''
 

Reference to dictionary object

$wpda_data_dictionary : \WPDataAccess\Data_Dictionary\WPDA_Dictionary_Exist

Default

 

Reference to import object

$wpda_import : \WPDataAccess\Utilities\WPDA_Import

Default

null
 

Reference to column list

$wpda_list_columns : \WPDataAccess\Data_Dictionary\WPDA_List_Columns

Default

 

Show, hide or empty

$wpda_main_favourites : string | null

Default

null
 

Table settings

$wpda_table_settings : null | object

Default

null

 Constants

 

Default value bulk actions enabled

DEFAULT_BULK_ACTIONS_ENABLED = true 
 

Default value bulk export enabled

DEFAULT_BULK_EXPORT_ENABLED = true 
 

Default value bulk search enabled

DEFAULT_SEARCH_BOX_ENABLED = true 
 

Base table for list of all tables

LIST_BASE_TABLE = 'information_schema.tables' 
 

LOADING

LOADING = 'Loading...' 
 

Make the default accessible to other classes

SEARCH_ITEM_NAME_DEFAULT = 'wpda_s'