has_items() ) : ?>
bulk_actions( $which ); ?>
extra_tablenav( $which );
add_filter( 'ngettext_default', array( $this, 'change_pagination_items_string' ), 10, 5 );
$this->pagination( $which );
remove_filter( 'ngettext_default', array( $this, 'change_pagination_items_string' ), 10, 5 );
?>
load( $item, true, true );
// Don't search corrupted tables, except when debug mode is enabled via $_GET parameter or WP_DEBUG constant.
if ( ! $debug && isset( $item['is_corrupted'] ) && $item['is_corrupted'] ) {
return false;
}
// Search from easy to hard, so that "expensive" code maybe doesn't have to run.
if ( false !== stripos( $item['id'], $term )
|| false !== stripos( $item['name'], $term )
|| false !== stripos( $item['description'], $term )
|| false !== stripos( TablePress::get_user_display_name( $item['author'] ), $term )
|| false !== stripos( TablePress::get_user_display_name( $item['options']['last_editor'] ), $term )
|| false !== stripos( TablePress::format_datetime( $item['last_modified'] ), $term )
|| false !== stripos( wp_json_encode( $item['data'], TABLEPRESS_JSON_OPTIONS ), $json_encoded_term ) ) {
return true;
}
return false;
}
/**
* Callback to for the array sort function.
*
* @since 1.0.0
*
* @param array $item_a First item that shall be compared to.
* @param array $item_b The second item for the comparison.
* @return int (-1, 0, 1) depending on which item sorts "higher".
*/
protected function _order_callback( array $item_a, array $item_b ) {
global $orderby, $order;
if ( 'last_modified_by' !== $orderby ) {
if ( $item_a[ $orderby ] === $item_b[ $orderby ] ) {
return 0;
}
} else {
if ( $item_a['options']['last_editor'] === $item_b['options']['last_editor'] ) {
return 0;
}
}
// Certain fields require some extra work before being sortable.
switch ( $orderby ) {
case 'last_modified':
// Compare UNIX timestamps for "last modified", which actually is a mySQL datetime string.
$result = ( strtotime( $item_a['last_modified'] ) > strtotime( $item_b['last_modified'] ) ) ? 1 : -1;
break;
case 'author':
// Get the actual author name, plain value is just the user ID.
$result = strnatcasecmp( TablePress::get_user_display_name( $item_a['author'] ), TablePress::get_user_display_name( $item_b['author'] ) );
break;
case 'last_modified_by':
// Get the actual last editor name, plain value is just the user ID.
$result = strnatcasecmp( TablePress::get_user_display_name( $item_a['options']['last_editor'] ), TablePress::get_user_display_name( $item_b['options']['last_editor'] ) );
break;
default:
// Other fields (ID, name, description) are sorted as strings.
$result = strnatcasecmp( $item_a[ $orderby ], $item_b[ $orderby ] );
}
return ( 'asc' === $order ) ? $result : - $result;
}
/**
* Prepares the list of items for displaying, by maybe searching and sorting, and by doing pagination.
*
* @since 1.0.0
*/
public function prepare_items() {
global $orderby, $order, $s;
wp_reset_vars( array( 'orderby', 'order', 's' ) );
// Maybe search in the items.
if ( $s ) {
$this->items = array_filter( $this->items, array( $this, '_search_callback' ) );
}
// Load actual tables after search for less memory consumption.
foreach ( $this->items as &$item ) {
// Don't load data, but load table options for access to last_editor.
$item = TablePress::$model_table->load( $item, false, true );
}
// Break reference in foreach iterator.
unset( $item );
// Maybe sort the items.
$_sortable_columns = $this->get_sortable_columns();
if ( $orderby && ! empty( $this->items ) && isset( $_sortable_columns[ "table_{$orderby}" ] ) ) {
usort( $this->items, array( $this, '_order_callback' ) );
}
// Number of records to show per page.
$per_page = $this->get_items_per_page( 'tablepress_list_per_page', 20 ); // Hard-coded, as in filter in Admin_Controller.
// Page number the user is currently viewing.
$current_page = $this->get_pagenum();
// Number of records in the array.
$total_items = count( $this->items );
// Slice items array to hold only items for the current page.
$this->items = array_slice( $this->items, ( ( $current_page - 1 ) * $per_page ), $per_page );
// Register pagination options and calculation results.
$this->set_pagination_args( array(
'total_items' => $total_items, // Total number of records/items.
'per_page' => $per_page, // Number of items per page.
'total_pages' => (int) ceil( $total_items / $per_page ), // Total number of pages.
) );
}
} // class TablePress_All_Tables_List_Table