On this page
WP_List_Table::ajax_response()
Handles an incoming ajax request (called from admin-ajax.php)
Source
File: wp-admin/includes/class-wp-list-table.php. View all references
public function ajax_response() {
$this->prepare_items();
ob_start();
if ( ! empty( $_REQUEST['no_placeholder'] ) ) {
$this->display_rows();
} else {
$this->display_rows_or_placeholder();
}
$rows = ob_get_clean();
$response = array( 'rows' => $rows );
if ( isset( $this->_pagination_args['total_items'] ) ) {
$response['total_items_i18n'] = sprintf(
/* translators: Number of items. */
_n( '%s item', '%s items', $this->_pagination_args['total_items'] ),
number_format_i18n( $this->_pagination_args['total_items'] )
);
}
if ( isset( $this->_pagination_args['total_pages'] ) ) {
$response['total_pages'] = $this->_pagination_args['total_pages'];
$response['total_pages_i18n'] = number_format_i18n( $this->_pagination_args['total_pages'] );
}
die( wp_json_encode( $response ) );
}
Related
Uses
| Uses | Description |
|---|---|
| WP_List_Table::display_rows() wp-admin/includes/class-wp-list-table.php | Generates the table rows. |
| WP_List_Table::display_rows_or_placeholder() wp-admin/includes/class-wp-list-table.php | Generates the tbody element for the list table. |
| WP_List_Table::prepare_items() wp-admin/includes/class-wp-list-table.php | Prepares the list of items for displaying. |
| _n() wp-includes/l10n.php | Translates and retrieves the singular or plural form based on the supplied number. |
| wp_json_encode() wp-includes/functions.php | Encodes a variable into JSON, with some sanity checks. |
| number_format_i18n() wp-includes/functions.php | Converts float number to format based on the locale. |
Used By
| Used By | Description |
|---|---|
| wp_ajax_fetch_list() wp-admin/includes/ajax-actions.php | Ajax handler for fetching a list table. |
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/ajax_response