'media', // Singular name of the listed records. 'plural' => 'media', // Plural name of the listed records. 'ajax' => false, // Does this table support ajax? ] ); } public function get_columns() { $columns = [ 'cb' => '', // Render a checkbox instead of text. 'preview' => _x( 'Preview', 'Column label', 'robin-image-optimizer' ), 'file' => _x( 'File path', 'Column label', 'robin-image-optimizer' ), 'folder' => _x( 'Folder', 'Column label', 'robin-image-optimizer' ), 'status' => _x( 'Status', 'Column label', 'robin-image-optimizer' ), 'optimization' => _x( 'Optimization', 'Column label', 'robin-image-optimizer' ), ]; return $columns; } public function prepare_items() { global $wpdb; $per_page = 20; $hidden = []; $columns = $this->get_columns(); $sortable = $this->get_sortable_columns(); $this->_column_headers = [ $columns, $hidden, $sortable ]; $current_page = $this->get_pagenum(); $offset = ( $current_page - 1 ) * $per_page; $folder_uid = WRIO_Plugin::app()->request->get( 'folder-filter', null, true ); $status = WRIO_Plugin::app()->request->get( 'status-filter', null, true ); if ( ! in_array( $status, [ 'success', 'unoptimized', 'error' ] ) ) { $status = null; } $db_table = RIO_Process_Queue::table_name(); $sql_filter = ''; if ( ! empty( $status ) ) { $sql_filter .= " AND result_status = '" . esc_sql( $status ) . "' "; } if ( ! empty( $folder_uid ) ) { $sql_filter .= " AND item_hash_alternative = '" . esc_sql( $folder_uid ) . "' "; } $total_items = $wpdb->get_var( " SELECT COUNT(*) FROM {$db_table} WHERE item_type = 'cf_image' {$sql_filter}" ); $rows = $wpdb->get_results( $wpdb->prepare( " SELECT * FROM {$db_table} WHERE item_type = 'cf_image' {$sql_filter} ORDER BY id DESC LIMIT %d OFFSET %d", $per_page, $offset ) ); if ( empty( $rows ) ) { $this->items = []; return; } foreach ( (array) $rows as $key => $row ) { $rows[ $key ] = new RIO_Process_Queue( $row ); } $this->items = $rows; $this->set_pagination_args( [ 'total_items' => $total_items, // WE have to calculate the total number of items. 'per_page' => $per_page, // WE have to determine how many items to show on a page. 'total_pages' => ceil( $total_items / $per_page ), // WE have to calculate the total number of pages. ] ); } public function display() { $cf = WRIO_Custom_Folders::get_instance(); $folders = $cf->getFolders(); $folder_uid = WRIO_Plugin::app()->request->get( 'folder-filter', null, true ); $status = WRIO_Plugin::app()->request->get( 'status-filter', null, true ); if ( ! in_array( $status, [ 'success', 'unoptimized', 'error' ] ) ) { $status = null; } $optimized_count = RIO_Process_Queue::count_by_type_status( 'cf_image', 'success' ); $unoptimized_count = RIO_Process_Queue::count_by_type_status( 'cf_image', 'unoptimized' ); $error_count = RIO_Process_Queue::count_by_type_status( 'cf_image', 'error' ); ?>
%s ', $folder );
}
}
/**
* @param RIO_Process_Queue $item
*/
protected function column_status( $item ) {
$statuses = [
'success' => __( 'Success', 'robin-image-optimizer' ),
'error' => __( 'Error', 'robin-image-optimizer' ),
'processing' => __( 'Processing', 'robin-image-optimizer' ),
'unoptimized' => __( 'Unoptimized', 'robin-image-optimizer' ),
'skip' => __( 'Skipped', 'robin-image-optimizer' ),
];
if ( isset( $statuses[ $item->get_result_status() ] ) ) {
echo esc_attr( $statuses[ $item->get_result_status() ] );
}
}
/**
* @param RIO_Process_Queue $item
*/
protected function column_optimization( $item ) {
$cf = WRIO_Custom_Folders::get_instance();
echo $cf->getMediaColumnContent( $item->get_id() );
}
protected function process_bulk_action() {
// Detect when a bulk action is being triggered.
if ( 'delete' === $this->current_action() ) {
wp_die( 'Items deleted(or they would be if we had items to delete)! ' );
}
}
}