forked from johnbillion/query-monitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmin.php
141 lines (116 loc) · 3.35 KB
/
admin.php
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php declare(strict_types = 1);
/**
* Admin screen collector.
*
* @package query-monitor
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* @extends QM_DataCollector<QM_Data_Admin>
*/
class QM_Collector_Admin extends QM_DataCollector {
public $id = 'response';
public function get_storage(): QM_Data {
return new QM_Data_Admin();
}
/**
* @return array<int, string>
*/
public function get_concerned_actions() {
$actions = array(
'current_screen',
'admin_notices',
'all_admin_notices',
'network_admin_notices',
'user_admin_notices',
);
if ( ! empty( $this->data->list_table ) ) {
$actions[] = $this->data->list_table['column_action'];
}
return $actions;
}
/**
* @return array<int, string>
*/
public function get_concerned_filters() {
$filters = array();
if ( ! empty( $this->data->list_table ) ) {
$filters[] = $this->data->list_table['columns_filter'];
$filters[] = $this->data->list_table['sortables_filter'];
}
return $filters;
}
/**
* @return void
*/
public function process() {
/**
* @var string $pagenow
* @var ?WP_List_Table $wp_list_table
*/
global $pagenow, $wp_list_table;
$this->data->pagenow = $pagenow;
$this->data->typenow = $GLOBALS['typenow'] ?? '';
$this->data->taxnow = $GLOBALS['taxnow'] ?? '';
$this->data->hook_suffix = $GLOBALS['hook_suffix'] ?? '';
$this->data->current_screen = get_current_screen();
$screens = array(
'edit' => true,
'edit-comments' => true,
'edit-tags' => true,
'link-manager' => true,
'plugins' => true,
'plugins-network' => true,
'sites-network' => true,
'themes-network' => true,
'upload' => true,
'users' => true,
'users-network' => true,
);
if ( empty( $this->data->current_screen ) || ! isset( $screens[ $this->data->current_screen->base ] ) ) {
return;
}
# And now, WordPress' legendary inconsistency comes into play:
$columns = $this->data->current_screen->id;
$sortables = $this->data->current_screen->id;
$column = $this->data->current_screen->base;
if ( ! empty( $this->data->current_screen->taxonomy ) ) {
$column = $this->data->current_screen->taxonomy;
} elseif ( ! empty( $this->data->current_screen->post_type ) ) {
$column = $this->data->current_screen->post_type . '_posts';
}
if ( ! empty( $this->data->current_screen->post_type ) && empty( $this->data->current_screen->taxonomy ) ) {
$columns = $this->data->current_screen->post_type . '_posts';
}
if ( 'edit-comments' === $column ) {
$column = 'comments';
} elseif ( 'upload' === $column ) {
$column = 'media';
} elseif ( 'link-manager' === $column ) {
$column = 'link';
}
$list_table_data = array(
'columns_filter' => "manage_{$columns}_columns",
'sortables_filter' => "manage_{$sortables}_sortable_columns",
'column_action' => "manage_{$column}_custom_column",
);
if ( ! empty( $wp_list_table ) ) {
$list_table_data['class_name'] = get_class( $wp_list_table );
}
$this->data->list_table = $list_table_data;
}
}
/**
* @param array<string, QM_Collector> $collectors
* @param QueryMonitor $qm
* @return array<string, QM_Collector>
*/
function register_qm_collector_admin( array $collectors, QueryMonitor $qm ) {
$collectors['response'] = new QM_Collector_Admin();
return $collectors;
}
if ( is_admin() ) {
add_filter( 'qm/collectors', 'register_qm_collector_admin', 10, 2 );
}