On this page
WP_List_Table::__construct( array|string $args = array() )
Constructor.
Description
The child class should call this constructor from its own constructor to override the default $args.
Parameters
$argsarray|string Optional-
Array or string of arguments.
pluralstringPlural value used for labels and the objects being listed.
This affects things such as CSS class-names and nonces used in the list table, e.g.'posts'.singularstringSingular label for an object being listed, e.g.'post'.
Default emptyajaxboolWhether the list table supports Ajax. This includes loading and sorting data, for example. If true, the class will call the _js_vars() method in the footer to provide variables to any scripts handling Ajax events. Default false.screenstringString containing the hook name used to determine the current screen. If left null, the current screen will be automatically set.
Default null.
Default:
array()
More Information
This sets default arguments and filters. Developers should override this, calling the parent constructor to provide values for singular and plural labels, as well as whether the class supports AJAX.
Source
File: wp-admin/includes/class-wp-list-table.php. View all references
public function __construct( $args = array() ) {
$args = wp_parse_args(
$args,
array(
'plural' => '',
'singular' => '',
'ajax' => false,
'screen' => null,
)
);
$this->screen = convert_to_screen( $args['screen'] );
add_filter( "manage_{$this->screen->id}_columns", array( $this, 'get_columns' ), 0 );
if ( ! $args['plural'] ) {
$args['plural'] = $this->screen->base;
}
$args['plural'] = sanitize_key( $args['plural'] );
$args['singular'] = sanitize_key( $args['singular'] );
$this->_args = $args;
if ( $args['ajax'] ) {
// wp_enqueue_script( 'list-table' );
add_action( 'admin_footer', array( $this, '_js_vars' ) );
}
if ( empty( $this->modes ) ) {
$this->modes = array(
'list' => __( 'Compact view' ),
'excerpt' => __( 'Extended view' ),
);
}
}
Related
Uses
| Uses | Description |
|---|---|
| convert_to_screen() wp-admin/includes/template.php | Converts a screen string to a screen object. |
| __() wp-includes/l10n.php | Retrieves the translation of $text. |
| sanitize_key() wp-includes/formatting.php | Sanitizes a string key. |
| wp_parse_args() wp-includes/functions.php | Merges user defined arguments into defaults array. |
| add_filter() wp-includes/plugin.php | Adds a callback function to a filter hook. |
| add_action() wp-includes/plugin.php | Adds a callback function to an action hook. |
Used By
| Used By | Description |
|---|---|
| WP_Plugins_List_Table::__construct() wp-admin/includes/class-wp-plugins-list-table.php | Constructor. |
| WP_Links_List_Table::__construct() wp-admin/includes/class-wp-links-list-table.php | Constructor. |
| WP_MS_Themes_List_Table::__construct() wp-admin/includes/class-wp-ms-themes-list-table.php | Constructor. |
| WP_Themes_List_Table::__construct() wp-admin/includes/class-wp-themes-list-table.php | Constructor. |
| WP_MS_Sites_List_Table::__construct() wp-admin/includes/class-wp-ms-sites-list-table.php | Constructor. |
| WP_Users_List_Table::__construct() wp-admin/includes/class-wp-users-list-table.php | Constructor. |
| WP_Media_List_Table::__construct() wp-admin/includes/class-wp-media-list-table.php | Constructor. |
| WP_Comments_List_Table::__construct() wp-admin/includes/class-wp-comments-list-table.php | Constructor. |
| WP_Terms_List_Table::__construct() wp-admin/includes/class-wp-terms-list-table.php | Constructor. |
| WP_Posts_List_Table::__construct() wp-admin/includes/class-wp-posts-list-table.php | Constructor. |
Changelog
| Version | Description |
|---|---|
| 3.1.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_list_table/__construct