Files
WP-LIT-MCP/tests/Stubs/WpListTable.php
T
janniclas.loosenandClaude Opus 5.5 0f23192873 feat: Protokoll tab as a core-style list table
The change summary is the wide primary column (key "title", so it cannot
be hidden) with the tool's human label below and row actions "Revision
ansehen" / "Objekt öffnen". Objects get human names ("Seite: Kontakt",
"Menü: …", "Einstellungen: Titel der Website"; deleted/trashed marked),
primed per page with one query each for posts, menus and users. Times are
relative within 24 h. Non-ok results show a badge and a marked row instead
of an Ergebnis column. Page size and columns via Screen Options; the tool
filter shows labels grouped by integration, dates have visible labels,
and an active filter offers "Filter zurücksetzen" (also in the empty state).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01At3V6SjwbMe6eMzVGW3Hs7
2026-09-26 19:02:47 +02:00

141 lines
4.3 KiB
PHP

<?php
declare(strict_types=1);
if (! class_exists('WP_List_Table')) {
/**
* Minimal stand-in for wp-admin/includes/class-wp-list-table.php: just enough of the
* real class's shape (constructor args, $items, single_row_columns dispatching to
* column_<name>()/column_default()) for LogListTable's own logic to be unit-tested
* without a full WP admin bootstrap.
*/
class WP_List_Table
{
/** @var list<array<string, mixed>> */
public $items = [];
/** @var array{0: array<string, string>, 1: list<string>, 2: list<string>}|null */
public $_column_headers;
/** @var array<string, mixed> */
protected $_args;
/** @var array<string, mixed> */
protected $_pagination_args = [];
/** @param array<string, mixed> $args */
public function __construct(array $args = [])
{
$this->_args = $args;
}
public function get_pagenum(): int
{
return isset($_GET['paged']) ? max(1, (int) $_GET['paged']) : 1; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
}
/** @param array<string, mixed> $args */
public function set_pagination_args(array $args): void
{
$this->_pagination_args = $args;
}
/** @return array<string, mixed> */
public function pagination_args(): array
{
return $this->_pagination_args;
}
/** @return array<string, string> */
public function get_columns(): array
{
return [];
}
public function single_row($item): void
{
echo '<tr>';
$this->single_row_columns($item);
echo '</tr>';
}
/** Like the real class: the per-page screen option of the current user, else the default. */
protected function get_items_per_page($option, $default_value = 20): int
{
$perPage = (int) get_user_option($option);
return $perPage < 1 ? $default_value : $perPage;
}
protected function get_default_primary_column_name()
{
$columns = $this->get_columns();
return (string) array_key_first($columns);
}
/** @param array<string, mixed> $item */
protected function single_row_columns($item): void
{
$primary = $this->get_default_primary_column_name();
foreach (array_keys($this->get_columns()) as $column_name) {
$method = 'column_' . $column_name;
$value = method_exists($this, $method) ? $this->{$method}($item) : $this->column_default($item, $column_name);
$value .= $this->handle_row_actions($item, $column_name, $primary);
printf('<td class="%s">%s</td>', $column_name, $value);
}
}
/** Like the real class: only the mobile toggle in the primary column. */
protected function handle_row_actions($item, $column_name, $primary)
{
return $column_name === $primary ? $this->toggleRow() : '';
}
/** @param array<string, string> $actions */
protected function row_actions($actions, $always_visible = false)
{
if ($actions === []) {
return '';
}
$links = [];
foreach ($actions as $action => $link) {
$links[] = "<span class='{$action}'>{$link}</span>";
}
return '<div class="row-actions">' . implode(' | ', $links) . '</div>' . $this->toggleRow();
}
private function toggleRow(): string
{
return '<button type="button" class="toggle-row"><span class="screen-reader-text">Show more details</span></button>';
}
/** @param array<string, mixed> $item */
protected function column_default($item, $column_name): string
{
return '';
}
public function no_items(): void
{
}
public function prepare_items(): void
{
}
/** Like the real class: the top table nav (with extra_tablenav()) comes before the rows. */
public function display(): void
{
$this->extra_tablenav('top');
}
/** @param string $which */
protected function extra_tablenav($which)
{
}
}
}