changeset 21 | 48c4eec2b7e6 |
parent 19 | 3d72ae0968f4 |
child 22 | 8c2e4d02f4ef |
20:7b1b88e27a20 | 21:48c4eec2b7e6 |
---|---|
29 * @var string $post_type The post type. |
29 * @var string $post_type The post type. |
30 */ |
30 */ |
31 protected $post_type = 'INVALID'; |
31 protected $post_type = 'INVALID'; |
32 |
32 |
33 /** |
33 /** |
34 * Get columns to show in the list table. |
34 * Gets columns to show in the list table. |
35 * |
35 * |
36 * @since 4.9.6 |
36 * @since 4.9.6 |
37 * |
37 * |
38 * @return string[] Array of column titles keyed by their column name. |
38 * @return string[] Array of column titles keyed by their column name. |
39 */ |
39 */ |
47 ); |
47 ); |
48 return $columns; |
48 return $columns; |
49 } |
49 } |
50 |
50 |
51 /** |
51 /** |
52 * Normalize the admin URL to the current page (by request_type). |
52 * Normalizes the admin URL to the current page (by request_type). |
53 * |
53 * |
54 * @since 5.3.0 |
54 * @since 5.3.0 |
55 * |
55 * |
56 * @return string URL to the current admin page. |
56 * @return string URL to the current admin page. |
57 */ |
57 */ |
64 |
64 |
65 return admin_url( $pagenow . '.php' ); |
65 return admin_url( $pagenow . '.php' ); |
66 } |
66 } |
67 |
67 |
68 /** |
68 /** |
69 * Get a list of sortable columns. |
69 * Gets a list of sortable columns. |
70 * |
70 * |
71 * @since 4.9.6 |
71 * @since 4.9.6 |
72 * |
72 * |
73 * @return array Default sortable columns. |
73 * @return array Default sortable columns. |
74 */ |
74 */ |
85 'created_timestamp' => array( 'requested', $desc_first ), |
85 'created_timestamp' => array( 'requested', $desc_first ), |
86 ); |
86 ); |
87 } |
87 } |
88 |
88 |
89 /** |
89 /** |
90 * Default primary column. |
90 * Returns the default primary column. |
91 * |
91 * |
92 * @since 4.9.6 |
92 * @since 4.9.6 |
93 * |
93 * |
94 * @return string Default primary column name. |
94 * @return string Default primary column name. |
95 */ |
95 */ |
96 protected function get_default_primary_column_name() { |
96 protected function get_default_primary_column_name() { |
97 return 'email'; |
97 return 'email'; |
98 } |
98 } |
99 |
99 |
100 /** |
100 /** |
101 * Count number of requests for each status. |
101 * Counts the number of requests for each status. |
102 * |
102 * |
103 * @since 4.9.6 |
103 * @since 4.9.6 |
104 * |
104 * |
105 * @global wpdb $wpdb WordPress database abstraction object. |
105 * @global wpdb $wpdb WordPress database abstraction object. |
106 * |
106 * |
135 |
135 |
136 return $counts; |
136 return $counts; |
137 } |
137 } |
138 |
138 |
139 /** |
139 /** |
140 * Get an associative array ( id => link ) with the list of views available on this table. |
140 * Gets an associative array ( id => link ) with the list of views available on this table. |
141 * |
141 * |
142 * @since 4.9.6 |
142 * @since 4.9.6 |
143 * |
143 * |
144 * @return string[] An array of HTML links keyed by their view. |
144 * @return string[] An array of HTML links keyed by their view. |
145 */ |
145 */ |
151 $total_requests = absint( array_sum( (array) $counts ) ); |
151 $total_requests = absint( array_sum( (array) $counts ) ); |
152 |
152 |
153 // Normalized admin URL. |
153 // Normalized admin URL. |
154 $admin_url = $this->get_admin_url(); |
154 $admin_url = $this->get_admin_url(); |
155 |
155 |
156 $current_link_attributes = empty( $current_status ) ? ' class="current" aria-current="page"' : ''; |
156 $status_label = sprintf( |
157 $status_label = sprintf( |
|
158 /* translators: %s: Number of requests. */ |
157 /* translators: %s: Number of requests. */ |
159 _nx( |
158 _nx( |
160 'All <span class="count">(%s)</span>', |
159 'All <span class="count">(%s)</span>', |
161 'All <span class="count">(%s)</span>', |
160 'All <span class="count">(%s)</span>', |
162 $total_requests, |
161 $total_requests, |
163 'requests' |
162 'requests' |
164 ), |
163 ), |
165 number_format_i18n( $total_requests ) |
164 number_format_i18n( $total_requests ) |
166 ); |
165 ); |
167 |
166 |
168 $views['all'] = sprintf( |
167 $views['all'] = array( |
169 '<a href="%s"%s>%s</a>', |
168 'url' => esc_url( $admin_url ), |
170 esc_url( $admin_url ), |
169 'label' => $status_label, |
171 $current_link_attributes, |
170 'current' => empty( $current_status ), |
172 $status_label |
|
173 ); |
171 ); |
174 |
172 |
175 foreach ( $statuses as $status => $label ) { |
173 foreach ( $statuses as $status => $label ) { |
176 $post_status = get_post_status_object( $status ); |
174 $post_status = get_post_status_object( $status ); |
177 if ( ! $post_status ) { |
175 if ( ! $post_status ) { |
178 continue; |
176 continue; |
179 } |
177 } |
180 |
178 |
181 $current_link_attributes = $status === $current_status ? ' class="current" aria-current="page"' : ''; |
179 $total_status_requests = absint( $counts->{$status} ); |
182 $total_status_requests = absint( $counts->{$status} ); |
|
183 |
180 |
184 if ( ! $total_status_requests ) { |
181 if ( ! $total_status_requests ) { |
185 continue; |
182 continue; |
186 } |
183 } |
187 |
184 |
190 number_format_i18n( $total_status_requests ) |
187 number_format_i18n( $total_status_requests ) |
191 ); |
188 ); |
192 |
189 |
193 $status_link = add_query_arg( 'filter-status', $status, $admin_url ); |
190 $status_link = add_query_arg( 'filter-status', $status, $admin_url ); |
194 |
191 |
195 $views[ $status ] = sprintf( |
192 $views[ $status ] = array( |
196 '<a href="%s"%s>%s</a>', |
193 'url' => esc_url( $status_link ), |
197 esc_url( $status_link ), |
194 'label' => $status_label, |
198 $current_link_attributes, |
195 'current' => $status === $current_status, |
199 $status_label |
|
200 ); |
196 ); |
201 } |
197 } |
202 |
198 |
203 return $views; |
199 return $this->get_views_links( $views ); |
204 } |
200 } |
205 |
201 |
206 /** |
202 /** |
207 * Get bulk actions. |
203 * Gets bulk actions. |
208 * |
204 * |
209 * @since 4.9.6 |
205 * @since 4.9.6 |
210 * |
206 * |
211 * @return array Array of bulk action labels keyed by their action. |
207 * @return array Array of bulk action labels keyed by their action. |
212 */ |
208 */ |
241 case 'resend': |
237 case 'resend': |
242 foreach ( $request_ids as $request_id ) { |
238 foreach ( $request_ids as $request_id ) { |
243 $resend = _wp_privacy_resend_request( $request_id ); |
239 $resend = _wp_privacy_resend_request( $request_id ); |
244 |
240 |
245 if ( $resend && ! is_wp_error( $resend ) ) { |
241 if ( $resend && ! is_wp_error( $resend ) ) { |
246 $count++; |
242 ++$count; |
247 } else { |
243 } else { |
248 $failures++; |
244 ++$failures; |
249 } |
245 } |
250 } |
246 } |
251 |
247 |
252 if ( $failures ) { |
248 if ( $failures ) { |
253 add_settings_error( |
249 add_settings_error( |
288 case 'complete': |
284 case 'complete': |
289 foreach ( $request_ids as $request_id ) { |
285 foreach ( $request_ids as $request_id ) { |
290 $result = _wp_privacy_completed_request( $request_id ); |
286 $result = _wp_privacy_completed_request( $request_id ); |
291 |
287 |
292 if ( $result && ! is_wp_error( $result ) ) { |
288 if ( $result && ! is_wp_error( $result ) ) { |
293 $count++; |
289 ++$count; |
294 } |
290 } |
295 } |
291 } |
296 |
292 |
297 add_settings_error( |
293 add_settings_error( |
298 'bulk_action', |
294 'bulk_action', |
311 break; |
307 break; |
312 |
308 |
313 case 'delete': |
309 case 'delete': |
314 foreach ( $request_ids as $request_id ) { |
310 foreach ( $request_ids as $request_id ) { |
315 if ( wp_delete_post( $request_id, true ) ) { |
311 if ( wp_delete_post( $request_id, true ) ) { |
316 $count++; |
312 ++$count; |
317 } else { |
313 } else { |
318 $failures++; |
314 ++$failures; |
319 } |
315 } |
320 } |
316 } |
321 |
317 |
322 if ( $failures ) { |
318 if ( $failures ) { |
323 add_settings_error( |
319 add_settings_error( |
356 break; |
352 break; |
357 } |
353 } |
358 } |
354 } |
359 |
355 |
360 /** |
356 /** |
361 * Prepare items to output. |
357 * Prepares items to output. |
362 * |
358 * |
363 * @since 4.9.6 |
359 * @since 4.9.6 |
364 * @since 5.1.0 Added support for column sorting. |
360 * @since 5.1.0 Added support for column sorting. |
365 */ |
361 */ |
366 public function prepare_items() { |
362 public function prepare_items() { |
409 ) |
405 ) |
410 ); |
406 ); |
411 } |
407 } |
412 |
408 |
413 /** |
409 /** |
414 * Checkbox column. |
410 * Returns the markup for the Checkbox column. |
415 * |
411 * |
416 * @since 4.9.6 |
412 * @since 4.9.6 |
417 * |
413 * |
418 * @param WP_User_Request $item Item being shown. |
414 * @param WP_User_Request $item Item being shown. |
419 * @return string Checkbox column markup. |
415 * @return string Checkbox column markup. |
420 */ |
416 */ |
421 public function column_cb( $item ) { |
417 public function column_cb( $item ) { |
422 return sprintf( '<input type="checkbox" name="request_id[]" value="%1$s" /><span class="spinner"></span>', esc_attr( $item->ID ) ); |
418 return sprintf( |
419 '<input type="checkbox" name="request_id[]" id="requester_%1$s" value="%1$s" />' . |
|
420 '<label for="requester_%1$s"><span class="screen-reader-text">%2$s</span></label><span class="spinner"></span>', |
|
421 esc_attr( $item->ID ), |
|
422 /* translators: Hidden accessibility text. %s: Email address. */ |
|
423 sprintf( __( 'Select %s' ), $item->email ) |
|
424 ); |
|
423 } |
425 } |
424 |
426 |
425 /** |
427 /** |
426 * Status column. |
428 * Status column. |
427 * |
429 * |
458 |
460 |
459 echo '</span>'; |
461 echo '</span>'; |
460 } |
462 } |
461 |
463 |
462 /** |
464 /** |
463 * Convert timestamp for display. |
465 * Converts a timestamp for display. |
464 * |
466 * |
465 * @since 4.9.6 |
467 * @since 4.9.6 |
466 * |
468 * |
467 * @param int $timestamp Event timestamp. |
469 * @param int $timestamp Event timestamp. |
468 * @return string Human readable date. |
470 * @return string Human readable date. |
481 |
483 |
482 return date_i18n( get_option( 'date_format' ), $timestamp ); |
484 return date_i18n( get_option( 'date_format' ), $timestamp ); |
483 } |
485 } |
484 |
486 |
485 /** |
487 /** |
486 * Default column handler. |
488 * Handles the default column. |
487 * |
489 * |
488 * @since 4.9.6 |
490 * @since 4.9.6 |
489 * @since 5.7.0 Added `manage_{$this->screen->id}_custom_column` action. |
491 * @since 5.7.0 Added `manage_{$this->screen->id}_custom_column` action. |
490 * |
492 * |
491 * @param WP_User_Request $item Item being shown. |
493 * @param WP_User_Request $item Item being shown. |
505 */ |
507 */ |
506 do_action( "manage_{$this->screen->id}_custom_column", $column_name, $item ); |
508 do_action( "manage_{$this->screen->id}_custom_column", $column_name, $item ); |
507 } |
509 } |
508 |
510 |
509 /** |
511 /** |
510 * Created timestamp column. Overridden by children. |
512 * Returns the markup for the Created timestamp column. Overridden by children. |
511 * |
513 * |
512 * @since 5.7.0 |
514 * @since 5.7.0 |
513 * |
515 * |
514 * @param WP_User_Request $item Item being shown. |
516 * @param WP_User_Request $item Item being shown. |
515 * @return string Human readable date. |
517 * @return string Human readable date. |
529 public function column_email( $item ) { |
531 public function column_email( $item ) { |
530 return sprintf( '<a href="%1$s">%2$s</a> %3$s', esc_url( 'mailto:' . $item->email ), $item->email, $this->row_actions( array() ) ); |
532 return sprintf( '<a href="%1$s">%2$s</a> %3$s', esc_url( 'mailto:' . $item->email ), $item->email, $this->row_actions( array() ) ); |
531 } |
533 } |
532 |
534 |
533 /** |
535 /** |
534 * Next steps column. Overridden by children. |
536 * Returns the markup for the next steps column. Overridden by children. |
535 * |
537 * |
536 * @since 4.9.6 |
538 * @since 4.9.6 |
537 * |
539 * |
538 * @param WP_User_Request $item Item being shown. |
540 * @param WP_User_Request $item Item being shown. |
539 */ |
541 */ |
553 $this->single_row_columns( $item ); |
555 $this->single_row_columns( $item ); |
554 echo '</tr>'; |
556 echo '</tr>'; |
555 } |
557 } |
556 |
558 |
557 /** |
559 /** |
558 * Embed scripts used to perform actions. Overridden by children. |
560 * Embeds scripts used to perform actions. Overridden by children. |
559 * |
561 * |
560 * @since 4.9.6 |
562 * @since 4.9.6 |
561 */ |
563 */ |
562 public function embed_scripts() {} |
564 public function embed_scripts() {} |
563 } |
565 } |