ListTable.php
1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
declare(strict_types=1);
namespace AC\ThirdParty\MediaLibraryAssistant;
use AC;
use MLA_List_Table;
use MLAData;
class ListTable implements AC\ListTable
{
private $table;
public function __construct(MLA_List_Table $table)
{
$this->table = $table;
}
public function get_column_value(string $column, int $id): string
{
$item = (object)MLAData::mla_get_attachment_by_id($id);
if ( ! $item) {
return '';
}
$method = 'column_' . $column;
if (method_exists($this->table, $method)) {
return (string)call_user_func([$this->table, $method], $item);
}
return (string)$this->table->column_default($item, $column);
}
public function get_total_items(): int
{
return $this->table->get_pagination_arg('total_items');
}
public function render_row(int $id): string
{
ob_start();
$this->table->single_row($this->get_attachment($id));
return ob_get_clean();
}
private function get_attachment(int $id): object
{
// Author column depends on this global to be set.
global $authordata;
$authordata = get_userdata(get_post_field('post_author', $id));
if ( ! class_exists('MLAData')) {
require_once(MLA_PLUGIN_PATH . 'includes/class-mla-data.php');
MLAData::initialize();
}
return (object)MLAData::mla_get_attachment_by_id($id);
}
}