'pixelkeep-record', 'plural' => 'pixelkeep-records', 'ajax' => false, ) ); } /** * Defines the columns. * * @return array */ public function get_columns(): array { return array( 'image' => __( 'Image', 'pixelkeep' ), 'size' => __( 'Size', 'pixelkeep' ), 'format' => __( 'Format', 'pixelkeep' ), 'before' => __( 'Before', 'pixelkeep' ), 'after' => __( 'After', 'pixelkeep' ), 'saved' => __( 'Saved', 'pixelkeep' ), 'method' => __( 'Method', 'pixelkeep' ), 'quality' => __( 'Quality', 'pixelkeep' ), 'status' => __( 'Status', 'pixelkeep' ), 'date' => __( 'Date', 'pixelkeep' ), ); } /** * Loads one page of rows. * * @return void */ public function prepare_items(): void { $this->_column_headers = array( $this->get_columns(), array(), array() ); $page = max( 1, $this->get_pagenum() ); $result = $this->records->paginate( $page, self::PER_PAGE, self::request_filters() ); $this->items = $result['rows']; $this->set_pagination_args( array( 'total_items' => $result['total'], 'per_page' => self::PER_PAGE, ) ); } /** * Message for an empty table. * * @return void */ public function no_items(): void { if ( array() !== array_filter( self::request_filters() ) ) { esc_html_e( 'No records match this search or filter.', 'pixelkeep' ); return; } esc_html_e( 'Nothing has been processed yet.', 'pixelkeep' ); } /** * Prints a cell. * * @param array $item Row. * @param string $column_name Column. * @return string Safe HTML. */ protected function column_default( $item, $column_name ): string { $before = (int) $item['bytes_before']; $after = (int) $item['bytes_after']; switch ( $column_name ) { case 'size': return sprintf( '%1$s
%2$d×%3$d', esc_html( (string) $item['size_name'] ), (int) $item['w_after'], (int) $item['h_after'] ); case 'format': return esc_html( strtoupper( (string) $item['format'] ) ); case 'before': return esc_html( Format::bytes( $before ) ); case 'after': return esc_html( Format::bytes( $after ) ); case 'saved': return esc_html( Format::saved_percent( $before, $after ) ); case 'method': return esc_html( (string) $item['method'] ); case 'quality': return null === $item['quality'] ? '—' : esc_html( (string) $item['quality'] ); case 'status': return Format::status_pill( (string) $item['status'], (string) $item['error_code'] ); case 'date': return esc_html( Format::date( (string) $item['updated_at'] ) ); } return ''; } /** * Prints the image cell. * * @param array $item Row. * @return string Safe HTML. */ protected function column_image( $item ): string { $id = (int) $item['attachment_id']; $title = get_the_title( $id ); $link = get_edit_post_link( $id ); if ( '' === $title ) { /* translators: %d: Attachment ID. */ $title = sprintf( __( 'Attachment #%d', 'pixelkeep' ), $id ); } return null === $link || '' === $link ? esc_html( $title ) : sprintf( '%2$s', esc_url( $link ), esc_html( $title ) ); } /** * Prints the status filter above the table. * * @param string $which `top` or `bottom`. * @return void */ protected function extra_tablenav( $which ): void { if ( 'top' !== $which ) { return; } $filters = self::request_filters(); $statuses = array( '' => __( 'All statuses', 'pixelkeep' ), 'optimized' => Format::status_label( 'optimized' ), 'already_optimal' => Format::status_label( 'already_optimal' ), 'skipped' => Format::status_label( 'skipped' ), 'failed' => Format::status_label( 'failed' ), 'restored' => Format::status_label( 'restored' ), ); $formats = array( '' => __( 'All formats', 'pixelkeep' ), 'jpeg' => 'JPEG', 'png' => 'PNG', 'gif' => 'GIF', 'webp' => 'WebP', 'avif' => 'AVIF', ); ?>
in_array( $status, array( 'optimized', 'already_optimal', 'skipped', 'failed', 'restored' ), true ) ? $status : '', 'format' => in_array( $format, array( 'jpeg', 'png', 'gif', 'webp', 'avif' ), true ) ? $format : '', 'search' => $search, ); } }