author | ymh <ymh.work@gmail.com> |
Mon, 08 Sep 2025 19:44:41 +0200 | |
changeset 23 | 417f20492bf7 |
parent 22 | 8c2e4d02f4ef |
permissions | -rw-r--r-- |
16 | 1 |
<?php |
2 |
/** |
|
3 |
* List Table API: WP_Privacy_Requests_Table class |
|
4 |
* |
|
5 |
* @package WordPress |
|
6 |
* @subpackage Administration |
|
7 |
* @since 4.9.6 |
|
8 |
*/ |
|
9 |
||
10 |
abstract class WP_Privacy_Requests_Table extends WP_List_Table { |
|
11 |
||
12 |
/** |
|
13 |
* Action name for the requests this table will work with. Classes |
|
14 |
* which inherit from WP_Privacy_Requests_Table should define this. |
|
15 |
* |
|
16 |
* Example: 'export_personal_data'. |
|
17 |
* |
|
18 |
* @since 4.9.6 |
|
19 |
* |
|
20 |
* @var string $request_type Name of action. |
|
21 |
*/ |
|
22 |
protected $request_type = 'INVALID'; |
|
23 |
||
24 |
/** |
|
25 |
* Post type to be used. |
|
26 |
* |
|
27 |
* @since 4.9.6 |
|
28 |
* |
|
29 |
* @var string $post_type The post type. |
|
30 |
*/ |
|
31 |
protected $post_type = 'INVALID'; |
|
32 |
||
33 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
34 |
* Gets columns to show in the list table. |
16 | 35 |
* |
36 |
* @since 4.9.6 |
|
37 |
* |
|
38 |
* @return string[] Array of column titles keyed by their column name. |
|
39 |
*/ |
|
40 |
public function get_columns() { |
|
41 |
$columns = array( |
|
42 |
'cb' => '<input type="checkbox" />', |
|
43 |
'email' => __( 'Requester' ), |
|
44 |
'status' => __( 'Status' ), |
|
45 |
'created_timestamp' => __( 'Requested' ), |
|
18 | 46 |
'next_steps' => __( 'Next steps' ), |
16 | 47 |
); |
48 |
return $columns; |
|
49 |
} |
|
50 |
||
51 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
52 |
* Normalizes the admin URL to the current page (by request_type). |
16 | 53 |
* |
54 |
* @since 5.3.0 |
|
55 |
* |
|
56 |
* @return string URL to the current admin page. |
|
57 |
*/ |
|
58 |
protected function get_admin_url() { |
|
59 |
$pagenow = str_replace( '_', '-', $this->request_type ); |
|
60 |
||
61 |
if ( 'remove-personal-data' === $pagenow ) { |
|
62 |
$pagenow = 'erase-personal-data'; |
|
63 |
} |
|
64 |
||
65 |
return admin_url( $pagenow . '.php' ); |
|
66 |
} |
|
67 |
||
68 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
69 |
* Gets a list of sortable columns. |
16 | 70 |
* |
71 |
* @since 4.9.6 |
|
72 |
* |
|
73 |
* @return array Default sortable columns. |
|
74 |
*/ |
|
75 |
protected function get_sortable_columns() { |
|
76 |
/* |
|
77 |
* The initial sorting is by 'Requested' (post_date) and descending. |
|
78 |
* With initial sorting, the first click on 'Requested' should be ascending. |
|
79 |
* With 'Requester' sorting active, the next click on 'Requested' should be descending. |
|
80 |
*/ |
|
81 |
$desc_first = isset( $_GET['orderby'] ); |
|
82 |
||
83 |
return array( |
|
84 |
'email' => 'requester', |
|
85 |
'created_timestamp' => array( 'requested', $desc_first ), |
|
86 |
); |
|
87 |
} |
|
88 |
||
89 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
90 |
* Returns the default primary column. |
16 | 91 |
* |
92 |
* @since 4.9.6 |
|
93 |
* |
|
94 |
* @return string Default primary column name. |
|
95 |
*/ |
|
96 |
protected function get_default_primary_column_name() { |
|
97 |
return 'email'; |
|
98 |
} |
|
99 |
||
100 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
101 |
* Counts the number of requests for each status. |
16 | 102 |
* |
103 |
* @since 4.9.6 |
|
104 |
* |
|
19 | 105 |
* @global wpdb $wpdb WordPress database abstraction object. |
106 |
* |
|
16 | 107 |
* @return object Number of posts for each status. |
108 |
*/ |
|
109 |
protected function get_request_counts() { |
|
110 |
global $wpdb; |
|
111 |
||
112 |
$cache_key = $this->post_type . '-' . $this->request_type; |
|
113 |
$counts = wp_cache_get( $cache_key, 'counts' ); |
|
114 |
||
115 |
if ( false !== $counts ) { |
|
116 |
return $counts; |
|
117 |
} |
|
118 |
||
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
119 |
$results = (array) $wpdb->get_results( |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
120 |
$wpdb->prepare( |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
121 |
"SELECT post_status, COUNT( * ) AS num_posts |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
122 |
FROM {$wpdb->posts} |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
123 |
WHERE post_type = %s |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
124 |
AND post_name = %s |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
125 |
GROUP BY post_status", |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
126 |
$this->post_type, |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
127 |
$this->request_type |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
128 |
), |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
129 |
ARRAY_A |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
130 |
); |
16 | 131 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
132 |
$counts = array_fill_keys( get_post_stati(), 0 ); |
16 | 133 |
|
134 |
foreach ( $results as $row ) { |
|
135 |
$counts[ $row['post_status'] ] = $row['num_posts']; |
|
136 |
} |
|
137 |
||
138 |
$counts = (object) $counts; |
|
139 |
wp_cache_set( $cache_key, $counts, 'counts' ); |
|
140 |
||
141 |
return $counts; |
|
142 |
} |
|
143 |
||
144 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
145 |
* Gets an associative array ( id => link ) with the list of views available on this table. |
16 | 146 |
* |
147 |
* @since 4.9.6 |
|
148 |
* |
|
149 |
* @return string[] An array of HTML links keyed by their view. |
|
150 |
*/ |
|
151 |
protected function get_views() { |
|
152 |
$current_status = isset( $_REQUEST['filter-status'] ) ? sanitize_text_field( $_REQUEST['filter-status'] ) : ''; |
|
153 |
$statuses = _wp_privacy_statuses(); |
|
154 |
$views = array(); |
|
155 |
$counts = $this->get_request_counts(); |
|
156 |
$total_requests = absint( array_sum( (array) $counts ) ); |
|
157 |
||
158 |
// Normalized admin URL. |
|
159 |
$admin_url = $this->get_admin_url(); |
|
160 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
161 |
$status_label = sprintf( |
16 | 162 |
/* translators: %s: Number of requests. */ |
163 |
_nx( |
|
164 |
'All <span class="count">(%s)</span>', |
|
165 |
'All <span class="count">(%s)</span>', |
|
166 |
$total_requests, |
|
167 |
'requests' |
|
168 |
), |
|
169 |
number_format_i18n( $total_requests ) |
|
170 |
); |
|
171 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
172 |
$views['all'] = array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
173 |
'url' => esc_url( $admin_url ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
174 |
'label' => $status_label, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
175 |
'current' => empty( $current_status ), |
16 | 176 |
); |
177 |
||
178 |
foreach ( $statuses as $status => $label ) { |
|
179 |
$post_status = get_post_status_object( $status ); |
|
180 |
if ( ! $post_status ) { |
|
181 |
continue; |
|
182 |
} |
|
183 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
184 |
$total_status_requests = absint( $counts->{$status} ); |
16 | 185 |
|
186 |
if ( ! $total_status_requests ) { |
|
187 |
continue; |
|
188 |
} |
|
189 |
||
190 |
$status_label = sprintf( |
|
191 |
translate_nooped_plural( $post_status->label_count, $total_status_requests ), |
|
192 |
number_format_i18n( $total_status_requests ) |
|
193 |
); |
|
194 |
||
195 |
$status_link = add_query_arg( 'filter-status', $status, $admin_url ); |
|
196 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
197 |
$views[ $status ] = array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
198 |
'url' => esc_url( $status_link ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
199 |
'label' => $status_label, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
200 |
'current' => $status === $current_status, |
16 | 201 |
); |
202 |
} |
|
203 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
204 |
return $this->get_views_links( $views ); |
16 | 205 |
} |
206 |
||
207 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
208 |
* Gets bulk actions. |
16 | 209 |
* |
210 |
* @since 4.9.6 |
|
211 |
* |
|
18 | 212 |
* @return array Array of bulk action labels keyed by their action. |
16 | 213 |
*/ |
214 |
protected function get_bulk_actions() { |
|
215 |
return array( |
|
18 | 216 |
'resend' => __( 'Resend confirmation requests' ), |
217 |
'complete' => __( 'Mark requests as completed' ), |
|
218 |
'delete' => __( 'Delete requests' ), |
|
16 | 219 |
); |
220 |
} |
|
221 |
||
222 |
/** |
|
223 |
* Process bulk actions. |
|
224 |
* |
|
225 |
* @since 4.9.6 |
|
18 | 226 |
* @since 5.6.0 Added support for the `complete` action. |
16 | 227 |
*/ |
228 |
public function process_bulk_action() { |
|
229 |
$action = $this->current_action(); |
|
230 |
$request_ids = isset( $_REQUEST['request_id'] ) ? wp_parse_id_list( wp_unslash( $_REQUEST['request_id'] ) ) : array(); |
|
231 |
||
18 | 232 |
if ( empty( $request_ids ) ) { |
233 |
return; |
|
234 |
} |
|
16 | 235 |
|
18 | 236 |
$count = 0; |
237 |
$failures = 0; |
|
238 |
||
239 |
check_admin_referer( 'bulk-privacy_requests' ); |
|
16 | 240 |
|
241 |
switch ( $action ) { |
|
242 |
case 'resend': |
|
243 |
foreach ( $request_ids as $request_id ) { |
|
244 |
$resend = _wp_privacy_resend_request( $request_id ); |
|
245 |
||
246 |
if ( $resend && ! is_wp_error( $resend ) ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
247 |
++$count; |
18 | 248 |
} else { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
249 |
++$failures; |
18 | 250 |
} |
251 |
} |
|
252 |
||
253 |
if ( $failures ) { |
|
254 |
add_settings_error( |
|
255 |
'bulk_action', |
|
256 |
'bulk_action', |
|
257 |
sprintf( |
|
258 |
/* translators: %d: Number of requests. */ |
|
259 |
_n( |
|
260 |
'%d confirmation request failed to resend.', |
|
261 |
'%d confirmation requests failed to resend.', |
|
262 |
$failures |
|
263 |
), |
|
264 |
$failures |
|
265 |
), |
|
266 |
'error' |
|
267 |
); |
|
268 |
} |
|
269 |
||
270 |
if ( $count ) { |
|
271 |
add_settings_error( |
|
272 |
'bulk_action', |
|
273 |
'bulk_action', |
|
274 |
sprintf( |
|
275 |
/* translators: %d: Number of requests. */ |
|
276 |
_n( |
|
277 |
'%d confirmation request re-sent successfully.', |
|
278 |
'%d confirmation requests re-sent successfully.', |
|
279 |
$count |
|
280 |
), |
|
281 |
$count |
|
282 |
), |
|
283 |
'success' |
|
284 |
); |
|
285 |
} |
|
286 |
||
287 |
break; |
|
288 |
||
289 |
case 'complete': |
|
290 |
foreach ( $request_ids as $request_id ) { |
|
291 |
$result = _wp_privacy_completed_request( $request_id ); |
|
292 |
||
293 |
if ( $result && ! is_wp_error( $result ) ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
294 |
++$count; |
16 | 295 |
} |
296 |
} |
|
297 |
||
298 |
add_settings_error( |
|
299 |
'bulk_action', |
|
300 |
'bulk_action', |
|
18 | 301 |
sprintf( |
302 |
/* translators: %d: Number of requests. */ |
|
303 |
_n( |
|
304 |
'%d request marked as complete.', |
|
305 |
'%d requests marked as complete.', |
|
306 |
$count |
|
307 |
), |
|
308 |
$count |
|
309 |
), |
|
16 | 310 |
'success' |
311 |
); |
|
312 |
break; |
|
18 | 313 |
|
314 |
case 'delete': |
|
315 |
foreach ( $request_ids as $request_id ) { |
|
316 |
if ( wp_delete_post( $request_id, true ) ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
317 |
++$count; |
18 | 318 |
} else { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
319 |
++$failures; |
18 | 320 |
} |
321 |
} |
|
322 |
||
323 |
if ( $failures ) { |
|
324 |
add_settings_error( |
|
325 |
'bulk_action', |
|
326 |
'bulk_action', |
|
327 |
sprintf( |
|
328 |
/* translators: %d: Number of requests. */ |
|
329 |
_n( |
|
330 |
'%d request failed to delete.', |
|
331 |
'%d requests failed to delete.', |
|
332 |
$failures |
|
333 |
), |
|
334 |
$failures |
|
335 |
), |
|
336 |
'error' |
|
337 |
); |
|
338 |
} |
|
339 |
||
340 |
if ( $count ) { |
|
341 |
add_settings_error( |
|
342 |
'bulk_action', |
|
343 |
'bulk_action', |
|
344 |
sprintf( |
|
345 |
/* translators: %d: Number of requests. */ |
|
346 |
_n( |
|
347 |
'%d request deleted successfully.', |
|
348 |
'%d requests deleted successfully.', |
|
349 |
$count |
|
350 |
), |
|
351 |
$count |
|
352 |
), |
|
353 |
'success' |
|
354 |
); |
|
355 |
} |
|
356 |
||
357 |
break; |
|
16 | 358 |
} |
359 |
} |
|
360 |
||
361 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
362 |
* Prepares items to output. |
16 | 363 |
* |
364 |
* @since 4.9.6 |
|
365 |
* @since 5.1.0 Added support for column sorting. |
|
366 |
*/ |
|
367 |
public function prepare_items() { |
|
368 |
$this->items = array(); |
|
369 |
$posts_per_page = $this->get_items_per_page( $this->request_type . '_requests_per_page' ); |
|
370 |
$args = array( |
|
371 |
'post_type' => $this->post_type, |
|
372 |
'post_name__in' => array( $this->request_type ), |
|
373 |
'posts_per_page' => $posts_per_page, |
|
374 |
'offset' => isset( $_REQUEST['paged'] ) ? max( 0, absint( $_REQUEST['paged'] ) - 1 ) * $posts_per_page : 0, |
|
375 |
'post_status' => 'any', |
|
376 |
's' => isset( $_REQUEST['s'] ) ? sanitize_text_field( $_REQUEST['s'] ) : '', |
|
377 |
); |
|
378 |
||
379 |
$orderby_mapping = array( |
|
380 |
'requester' => 'post_title', |
|
381 |
'requested' => 'post_date', |
|
382 |
); |
|
383 |
||
384 |
if ( isset( $_REQUEST['orderby'] ) && isset( $orderby_mapping[ $_REQUEST['orderby'] ] ) ) { |
|
385 |
$args['orderby'] = $orderby_mapping[ $_REQUEST['orderby'] ]; |
|
386 |
} |
|
387 |
||
388 |
if ( isset( $_REQUEST['order'] ) && in_array( strtoupper( $_REQUEST['order'] ), array( 'ASC', 'DESC' ), true ) ) { |
|
389 |
$args['order'] = strtoupper( $_REQUEST['order'] ); |
|
390 |
} |
|
391 |
||
392 |
if ( ! empty( $_REQUEST['filter-status'] ) ) { |
|
393 |
$filter_status = isset( $_REQUEST['filter-status'] ) ? sanitize_text_field( $_REQUEST['filter-status'] ) : ''; |
|
394 |
$args['post_status'] = $filter_status; |
|
395 |
} |
|
396 |
||
397 |
$requests_query = new WP_Query( $args ); |
|
398 |
$requests = $requests_query->posts; |
|
399 |
||
400 |
foreach ( $requests as $request ) { |
|
401 |
$this->items[] = wp_get_user_request( $request->ID ); |
|
402 |
} |
|
403 |
||
404 |
$this->items = array_filter( $this->items ); |
|
405 |
||
406 |
$this->set_pagination_args( |
|
407 |
array( |
|
408 |
'total_items' => $requests_query->found_posts, |
|
409 |
'per_page' => $posts_per_page, |
|
410 |
) |
|
411 |
); |
|
412 |
} |
|
413 |
||
414 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
415 |
* Returns the markup for the Checkbox column. |
16 | 416 |
* |
417 |
* @since 4.9.6 |
|
418 |
* |
|
419 |
* @param WP_User_Request $item Item being shown. |
|
420 |
* @return string Checkbox column markup. |
|
421 |
*/ |
|
422 |
public function column_cb( $item ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
423 |
return sprintf( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
424 |
'<input type="checkbox" name="request_id[]" id="requester_%1$s" value="%1$s" />' . |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
425 |
'<label for="requester_%1$s"><span class="screen-reader-text">%2$s</span></label><span class="spinner"></span>', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
426 |
esc_attr( $item->ID ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
427 |
/* translators: Hidden accessibility text. %s: Email address. */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
428 |
sprintf( __( 'Select %s' ), $item->email ) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
429 |
); |
16 | 430 |
} |
431 |
||
432 |
/** |
|
433 |
* Status column. |
|
434 |
* |
|
435 |
* @since 4.9.6 |
|
436 |
* |
|
437 |
* @param WP_User_Request $item Item being shown. |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
438 |
* @return string|void Status column markup. Returns a string if no status is found, |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
439 |
* otherwise it displays the markup. |
16 | 440 |
*/ |
441 |
public function column_status( $item ) { |
|
442 |
$status = get_post_status( $item->ID ); |
|
443 |
$status_object = get_post_status_object( $status ); |
|
444 |
||
445 |
if ( ! $status_object || empty( $status_object->label ) ) { |
|
446 |
return '-'; |
|
447 |
} |
|
448 |
||
449 |
$timestamp = false; |
|
450 |
||
451 |
switch ( $status ) { |
|
452 |
case 'request-confirmed': |
|
453 |
$timestamp = $item->confirmed_timestamp; |
|
454 |
break; |
|
455 |
case 'request-completed': |
|
456 |
$timestamp = $item->completed_timestamp; |
|
457 |
break; |
|
458 |
} |
|
459 |
||
460 |
echo '<span class="status-label status-' . esc_attr( $status ) . '">'; |
|
461 |
echo esc_html( $status_object->label ); |
|
462 |
||
463 |
if ( $timestamp ) { |
|
464 |
echo ' (' . $this->get_timestamp_as_date( $timestamp ) . ')'; |
|
465 |
} |
|
466 |
||
467 |
echo '</span>'; |
|
468 |
} |
|
469 |
||
470 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
471 |
* Converts a timestamp for display. |
16 | 472 |
* |
473 |
* @since 4.9.6 |
|
474 |
* |
|
475 |
* @param int $timestamp Event timestamp. |
|
476 |
* @return string Human readable date. |
|
477 |
*/ |
|
478 |
protected function get_timestamp_as_date( $timestamp ) { |
|
479 |
if ( empty( $timestamp ) ) { |
|
480 |
return ''; |
|
481 |
} |
|
482 |
||
483 |
$time_diff = time() - $timestamp; |
|
484 |
||
485 |
if ( $time_diff >= 0 && $time_diff < DAY_IN_SECONDS ) { |
|
486 |
/* translators: %s: Human-readable time difference. */ |
|
487 |
return sprintf( __( '%s ago' ), human_time_diff( $timestamp ) ); |
|
488 |
} |
|
489 |
||
490 |
return date_i18n( get_option( 'date_format' ), $timestamp ); |
|
491 |
} |
|
492 |
||
493 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
494 |
* Handles the default column. |
16 | 495 |
* |
496 |
* @since 4.9.6 |
|
18 | 497 |
* @since 5.7.0 Added `manage_{$this->screen->id}_custom_column` action. |
16 | 498 |
* |
499 |
* @param WP_User_Request $item Item being shown. |
|
500 |
* @param string $column_name Name of column being shown. |
|
501 |
*/ |
|
502 |
public function column_default( $item, $column_name ) { |
|
18 | 503 |
/** |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
504 |
* Fires for each custom column of a specific request type in the Privacy Requests list table. |
18 | 505 |
* |
506 |
* Custom columns are registered using the {@see 'manage_export-personal-data_columns'} |
|
507 |
* and the {@see 'manage_erase-personal-data_columns'} filters. |
|
508 |
* |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
509 |
* The dynamic portion of the hook name, `$this->screen->id`, refers to the ID given to the list table |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
510 |
* according to which screen it's displayed on. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
511 |
* |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
512 |
* Possible hook names include: |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
513 |
* |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
514 |
* - `manage_export-personal-data_custom_column` |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
515 |
* - `manage_erase-personal-data_custom_column` |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
516 |
* |
18 | 517 |
* @since 5.7.0 |
518 |
* |
|
519 |
* @param string $column_name The name of the column to display. |
|
520 |
* @param WP_User_Request $item The item being shown. |
|
521 |
*/ |
|
522 |
do_action( "manage_{$this->screen->id}_custom_column", $column_name, $item ); |
|
523 |
} |
|
16 | 524 |
|
18 | 525 |
/** |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
526 |
* Returns the markup for the Created timestamp column. Overridden by children. |
18 | 527 |
* |
528 |
* @since 5.7.0 |
|
529 |
* |
|
530 |
* @param WP_User_Request $item Item being shown. |
|
531 |
* @return string Human readable date. |
|
532 |
*/ |
|
533 |
public function column_created_timestamp( $item ) { |
|
534 |
return $this->get_timestamp_as_date( $item->created_timestamp ); |
|
16 | 535 |
} |
536 |
||
537 |
/** |
|
538 |
* Actions column. Overridden by children. |
|
539 |
* |
|
540 |
* @since 4.9.6 |
|
541 |
* |
|
542 |
* @param WP_User_Request $item Item being shown. |
|
543 |
* @return string Email column markup. |
|
544 |
*/ |
|
545 |
public function column_email( $item ) { |
|
546 |
return sprintf( '<a href="%1$s">%2$s</a> %3$s', esc_url( 'mailto:' . $item->email ), $item->email, $this->row_actions( array() ) ); |
|
547 |
} |
|
548 |
||
549 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
550 |
* Returns the markup for the next steps column. Overridden by children. |
16 | 551 |
* |
552 |
* @since 4.9.6 |
|
553 |
* |
|
554 |
* @param WP_User_Request $item Item being shown. |
|
555 |
*/ |
|
556 |
public function column_next_steps( $item ) {} |
|
557 |
||
558 |
/** |
|
559 |
* Generates content for a single row of the table, |
|
560 |
* |
|
561 |
* @since 4.9.6 |
|
562 |
* |
|
563 |
* @param WP_User_Request $item The current item. |
|
564 |
*/ |
|
565 |
public function single_row( $item ) { |
|
566 |
$status = $item->status; |
|
567 |
||
568 |
echo '<tr id="request-' . esc_attr( $item->ID ) . '" class="status-' . esc_attr( $status ) . '">'; |
|
569 |
$this->single_row_columns( $item ); |
|
570 |
echo '</tr>'; |
|
571 |
} |
|
572 |
||
573 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
574 |
* Embeds scripts used to perform actions. Overridden by children. |
16 | 575 |
* |
576 |
* @since 4.9.6 |
|
577 |
*/ |
|
578 |
public function embed_scripts() {} |
|
579 |
} |