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 7.6.8 7.6.9 7.7.0 7.8.0 7.8.1 7.8.10 7.8.11 7.8.12 7.8.13 7.8.14 7.8.15 7.8.16 7.8.17 7.8.18 7.8.2 7.8.3 7.8.4 7.8.5 7.8.5.1 7.8.6 7.8.7 7.8.8 7.8.9 7.9.0 7.9.1 7.9.10 7.9.11 7.9.2 7.9.3 7.9.4 7.9.5 7.9.6 7.9.7 7.9.8 7.9.9 8.0.0 8.0.1 8.0.2 8.0.3 8.0.4 8.0.5 8.0.6 8.0.7 8.0.8 8.1.0 8.1.1 8.1.2 8.1.3 8.1.4 8.2.0 trunk 1.0.0 1.1.0 1.2.0 1.3.0 1.4.0 1.5.0 1.6.0 1.7.0 1.8.0 1.9.0 2.0.0 2.1.0 2.2.0 2.3.0 2.4.0 2.5.0 2.6.0 2.7.0 2.8.0 2.8.1 2.8.2 2.8.3 2.9.0 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.1.0 3.2.0 3.3.0 3.4.0 3.5.0 3.6.1 3.7.0 3.8.0 3.9.0 3.9.1 3.9.2 4.0.0 4.0.1 4.1.0 4.2.0 4.2.1 4.2.2 4.3.0 4.3.1 4.4.0 4.5.0 4.6.0 4.7.0 4.7.1 4.7.2 4.7.3 4.7.4 4.8.0 4.8.1 4.8.2 4.8.3 4.9.0 4.9.1 4.9.2 4.9.3 5.0.0
admin-site-enhancements / classes / class-enhance-list-tables.php
admin-site-enhancements / classes Last commit date
class-activation.php 1 year ago class-admin-columns-manager.php 1 year ago class-admin-menu-organizer.php 1 year ago class-auto-publish-posts-with-missed-schedule.php 1 year ago class-avif-upload.php 1 year ago class-change-login-url.php 1 year ago class-cleanup-admin-bar.php 1 year ago class-code-snippets-manager.php 1 year ago class-common-methods.php 1 year ago class-content-duplication.php 1 year ago class-content-order.php 1 year ago class-custom-admin-footer-text.php 1 year ago class-custom-body-class.php 1 year ago class-custom-content-types.php 1 year ago class-custom-css.php 1 year ago class-custom-nav-menu-items-in-new-tab.php 1 year ago class-deactivation.php 1 year ago class-disable-comments.php 1 year ago class-disable-dashboard-widgets.php 1 year ago class-disable-feeds.php 1 year ago class-disable-gutenberg.php 1 year ago class-disable-rest-api.php 1 year ago class-disable-smaller-components.php 1 year ago class-disable-updates.php 1 year ago class-disable-xml-rpc.php 1 year ago class-display-system-summary.php 1 year ago class-email-address-obfuscator.php 1 year ago class-email-delivery.php 1 year ago class-enhance-list-tables.php 1 year ago class-external-permalinks.php 1 year ago class-heartbeat-control.php 1 year ago class-hide-admin-bar.php 1 year ago class-hide-admin-notices.php 1 year ago class-image-sizes-panel.php 1 year ago class-image-upload-control.php 1 year ago class-insert-head-body-footer-code.php 1 year ago class-last-login-column.php 1 year ago class-limit-login-attempts.php 1 year ago class-login-id-type.php 1 year ago class-login-logout-menu.php 1 year ago class-maintenance-mode.php 1 year ago class-manage-ads-appads-txt.php 1 year ago class-manage-robots-txt.php 1 year ago class-media-replacement.php 1 year ago class-multiple-user-roles.php 1 year ago class-obfuscate-author-slugs.php 1 year ago class-open-external-links-in-new-tab.php 1 year ago class-password-protection.php 1 year ago class-redirect-after-login.php 1 year ago class-redirect-after-logout.php 1 year ago class-redirect-fourofour.php 1 year ago class-revisions-control.php 1 year ago class-search-engines-visibility.php 1 year ago class-settings-fields-render.php 1 year ago class-settings-sanitization.php 1 year ago class-settings-sections-fields.php 1 year ago class-show-custom-taxonomy-filters.php 1 year ago class-site-identity-on-login-page.php 1 year ago class-svg-upload.php 1 year ago class-various-admin-ui-enhancements.php 1 year ago class-view-admin-as-role.php 1 year ago class-wider-admin-menu.php 1 year ago
class-enhance-list-tables.php
504 lines
1 <?php
2
3 namespace ASENHA\Classes;
4
5 /**
6 * Class for Enhance List Tables module
7 *
8 * @since 6.9.5
9 */
10 class Enhance_List_Tables {
11 /**
12 * Current post type. For Content Admin >> Show Custom Taxonomy Filters functionality.
13 */
14 public $post_type;
15
16 /**
17 * Show featured images column in list tables for pages and post types that support featured image
18 *
19 * @since 1.0.0
20 */
21 public function show_featured_image_column() {
22 $post_types = get_post_types( array(
23 'public' => true,
24 ), 'names' );
25 foreach ( $post_types as $post_type_key => $post_type_name ) {
26 if ( post_type_supports( $post_type_key, 'thumbnail' ) ) {
27 add_filter( "manage_{$post_type_name}_posts_columns", [$this, 'add_featured_image_column'], 999 );
28 add_action(
29 "manage_{$post_type_name}_posts_custom_column",
30 [$this, 'add_featured_image'],
31 10,
32 2
33 );
34 }
35 }
36 }
37
38 /**
39 * Add a column called Featured Image as the first column
40 *
41 * @param mixed $columns
42 * @return void
43 * @since 1.0.0
44 */
45 public function add_featured_image_column( $columns ) {
46 $new_columns = array();
47 foreach ( $columns as $key => $value ) {
48 if ( 'title' == $key ) {
49 // We add featured image column before the 'title' column
50 $new_columns['asenha-featured-image'] = __( 'Featured Image', 'admin-site-enhancements' );
51 }
52 if ( 'thumb' == $key ) {
53 // For WooCommerce products, we add featured image column before it's native thumbnail column
54 $new_columns['asenha-featured-image'] = __( 'Product Image', 'admin-site-enhancements' );
55 }
56 $new_columns[$key] = $value;
57 }
58 // Replace WooCommerce thumbnail column with ASE featured image column
59 if ( array_key_exists( 'thumb', $new_columns ) ) {
60 unset($new_columns['thumb']);
61 }
62 return $new_columns;
63 }
64
65 /**
66 * Echo featured image's in thumbnail size to a column
67 *
68 * @param mixed $column_name
69 * @param mixed $id
70 * @since 1.0.0
71 */
72 public function add_featured_image( $column_name, $id ) {
73 if ( 'asenha-featured-image' === $column_name ) {
74 if ( has_post_thumbnail( $id ) ) {
75 $size = 'thumbnail';
76 echo get_the_post_thumbnail( $id, $size, '' );
77 } else {
78 echo '<img src="' . esc_url( plugins_url( 'assets/img/default_featured_image.jpg', __DIR__ ) ) . '" />';
79 }
80 }
81 }
82
83 /**
84 * Show excerpt column in list tables for pages and post types that support excerpt.
85 *
86 * @since 1.0.0
87 */
88 public function show_excerpt_column() {
89 $post_types = get_post_types( array(
90 'public' => true,
91 ), 'names' );
92 foreach ( $post_types as $post_type_key => $post_type_name ) {
93 if ( post_type_supports( $post_type_key, 'excerpt' ) ) {
94 add_filter( "manage_{$post_type_name}_posts_columns", [$this, 'add_excerpt_column'] );
95 add_action(
96 "manage_{$post_type_name}_posts_custom_column",
97 [$this, 'add_excerpt'],
98 10,
99 2
100 );
101 }
102 }
103 }
104
105 /**
106 * Add a column called Excerpt as the first column
107 *
108 * @param mixed $columns
109 * @return void
110 * @since 1.0.0
111 */
112 public function add_excerpt_column( $columns ) {
113 $new_columns = array();
114 foreach ( $columns as $key => $value ) {
115 $new_columns[$key] = $value;
116 if ( $key == 'title' ) {
117 $new_columns['asenha-excerpt'] = __( 'Excerpt', 'admin-site-enhancements' );
118 }
119 }
120 return $new_columns;
121 }
122
123 /**
124 * Echo featured image's in thumbnail size to a column
125 *
126 * @param mixed $column_name
127 * @param mixed $id
128 * @since 1.0.0
129 */
130 public function add_excerpt( $column_name, $id ) {
131 if ( 'asenha-excerpt' === $column_name ) {
132 $excerpt = get_the_excerpt( $id );
133 // about 310 characters
134 $excerpt = substr( $excerpt, 0, 160 );
135 // truncate to 160 characters
136 $short_excerpt = substr( $excerpt, 0, strrpos( $excerpt, ' ' ) );
137 echo wp_kses_post( $short_excerpt );
138 }
139 }
140
141 /**
142 * Show last modified column for pages, posts and CPTs
143 *
144 * @since 7.4.0
145 */
146 public function show_last_modified_column() {
147 foreach ( get_post_types() as $post_type ) {
148 add_filter(
149 'manage_' . $post_type . '_posts_columns',
150 [$this, 'add_last_modified_column'],
151 10,
152 1
153 );
154 add_action(
155 'manage_' . $post_type . '_posts_custom_column',
156 [$this, 'show_last_modified_datetime'],
157 10,
158 2
159 );
160 add_action(
161 'manage_edit-' . $post_type . '_sortable_columns',
162 [$this, 'make_last_modified_column_sortable'],
163 10,
164 1
165 );
166 }
167 }
168
169 /**
170 * Add a column called Last Modified
171 *
172 * @since 7.4.0
173 */
174 public function add_last_modified_column( $columns ) {
175 $new_columns = array();
176 foreach ( $columns as $key => $value ) {
177 $new_columns[$key] = $value;
178 if ( $key == 'date' ) {
179 $new_columns['asenha-last-modified'] = __( 'Last Modified', 'admin-site-enhancements' );
180 }
181 }
182 return $new_columns;
183 }
184
185 /**
186 * Output the last modified date time for each post
187 *
188 * @since 7.4.0
189 */
190 public function show_last_modified_datetime( $column_name, $id ) {
191 if ( 'asenha-last-modified' == $column_name ) {
192 echo '<span class="last-modified-timestamp">' . get_the_modified_date( 'Y/m/d' ) . '<br />' . get_the_modified_time( 'g:i a' ) . '</span>';
193 }
194 }
195
196 /**
197 * Make last modified column sortable
198 *
199 * @since 7.4.0
200 */
201 public function make_last_modified_column_sortable() {
202 $columns['asenha-last-modified'] = 'modified';
203 return $columns;
204 }
205
206 /**
207 * Add ID column list table of pages, posts, custom post types, media, taxonomies, custom taxonomies, users amd comments
208 *
209 * @since 1.0.0
210 */
211 public function show_id_column() {
212 // For pages and hierarchical post types list table
213 add_filter( 'manage_pages_columns', [$this, 'add_id_column'] );
214 add_action(
215 'manage_pages_custom_column',
216 [$this, 'add_id_echo_value'],
217 10,
218 2
219 );
220 // For posts and non-hierarchical custom posts list table
221 add_filter( 'manage_posts_columns', [$this, 'add_id_column'] );
222 add_action(
223 'manage_posts_custom_column',
224 [$this, 'add_id_echo_value'],
225 10,
226 2
227 );
228 // For media list table
229 add_filter( 'manage_media_columns', [$this, 'add_id_column'] );
230 add_action(
231 'manage_media_custom_column',
232 [$this, 'add_id_echo_value'],
233 10,
234 2
235 );
236 // For list table of all taxonomies
237 $taxonomies = get_taxonomies( [
238 'public' => true,
239 ], 'names' );
240 foreach ( $taxonomies as $taxonomy ) {
241 add_filter( 'manage_edit-' . $taxonomy . '_columns', [$this, 'add_id_column'] );
242 add_action(
243 'manage_' . $taxonomy . '_custom_column',
244 [$this, 'add_id_return_value'],
245 10,
246 3
247 );
248 }
249 // For users list table
250 add_filter( 'manage_users_columns', [$this, 'add_id_column'] );
251 add_action(
252 'manage_users_custom_column',
253 [$this, 'add_id_return_value'],
254 10,
255 3
256 );
257 // For comments list table
258 add_filter( 'manage_edit-comments_columns', [$this, 'add_id_column'] );
259 add_action(
260 'manage_comments_custom_column',
261 [$this, 'add_id_echo_value'],
262 10,
263 3
264 );
265 }
266
267 /**
268 * Add a column called ID
269 *
270 * @param mixed $columns
271 * @return void
272 * @since 1.0.0
273 */
274 public function add_id_column( $columns ) {
275 $columns['asenha-id'] = 'ID';
276 return $columns;
277 }
278
279 /**
280 * Echo post ID value to a column
281 *
282 * @param mixed $column_name
283 * @param mixed $id
284 * @since 1.0.0
285 */
286 public function add_id_echo_value( $column_name, $id ) {
287 if ( 'asenha-id' === $column_name ) {
288 echo esc_html( $id );
289 }
290 }
291
292 /**
293 * Return post ID value to a column
294 *
295 * @param mixed $value
296 * @param mixed $column_name
297 * @param mixed $id
298 * @since 1.0.0
299 */
300 public function add_id_return_value( $value, $column_name, $id ) {
301 if ( 'asenha-id' === $column_name ) {
302 $value = $id;
303 }
304 return $value;
305 }
306
307 /**
308 * Add file size column to media library
309 *
310 * @since 6.9.5
311 */
312 public function add_column_file_size( $columns ) {
313 $columns['asenha-file-size'] = __( 'File Size', 'admin-site-enhancements' );
314 return $columns;
315 }
316
317 /**
318 * Display the file size value
319 *
320 * @since 6.9.5
321 */
322 public function display_file_size( $column_name, $attachment_id ) {
323 if ( 'asenha-file-size' != $column_name ) {
324 return;
325 }
326 $file_size = filesize( get_attached_file( $attachment_id ) );
327 $file_size = size_format( $file_size, 1 );
328 // Show one decimal point
329 echo esc_html( $file_size );
330 }
331
332 /**
333 * Add file size column to media library
334 *
335 * @since 6.9.5
336 */
337 public function add_media_styles() {
338 echo '<style>.column-asenha-file-siz {width: 60px;}</style>';
339 }
340
341 /**
342 * Add ID in the action row of list tables for pages, posts, custom post types, media, taxonomies, custom taxonomies, users amd comments
343 *
344 * @since 4.7.4
345 */
346 public function show_id_in_action_row() {
347 add_filter(
348 'page_row_actions',
349 array($this, 'add_id_in_action_row'),
350 10,
351 2
352 );
353 add_filter(
354 'post_row_actions',
355 array($this, 'add_id_in_action_row'),
356 10,
357 2
358 );
359 add_filter(
360 'cat_row_actions',
361 array($this, 'add_id_in_action_row'),
362 10,
363 2
364 );
365 add_filter(
366 'tag_row_actions',
367 array($this, 'add_id_in_action_row'),
368 10,
369 2
370 );
371 add_filter(
372 'media_row_actions',
373 array($this, 'add_id_in_action_row'),
374 10,
375 2
376 );
377 add_filter(
378 'comment_row_actions',
379 array($this, 'add_id_in_action_row'),
380 10,
381 2
382 );
383 add_filter(
384 'user_row_actions',
385 array($this, 'add_id_in_action_row'),
386 10,
387 2
388 );
389 }
390
391 /**
392 * Output the ID in the action row
393 *
394 * @since 4.7.4
395 */
396 public function add_id_in_action_row( $actions, $object ) {
397 if ( current_user_can( 'edit_posts' ) ) {
398 // For pages, posts, custom post types, media/attachments, users
399 if ( property_exists( $object, 'ID' ) ) {
400 $id = $object->ID;
401 }
402 // For taxonomies
403 if ( property_exists( $object, 'term_id' ) ) {
404 $id = $object->term_id;
405 }
406 // For comments
407 if ( property_exists( $object, 'comment_ID' ) ) {
408 $id = $object->comment_ID;
409 }
410 $actions['asenha-list-table-item-id'] = '<span class="asenha-list-table-item-id">ID: ' . $id . '</span>';
411 }
412 return $actions;
413 }
414
415 /**
416 * Show last modified column for pages, posts and CPTs
417 *
418 * @since 7.4.0
419 */
420 public function hide_date_column() {
421 foreach ( get_post_types() as $post_type ) {
422 add_filter(
423 'manage_' . $post_type . '_posts_columns',
424 [$this, 'remove_date_column'],
425 10,
426 1
427 );
428 }
429 }
430
431 /**
432 * Add a column called Last Modified
433 *
434 * @since 7.4.0
435 */
436 public function remove_date_column( $columns ) {
437 unset($columns['date']);
438 return $columns;
439 }
440
441 /**
442 * Hide comments column in list tables for pages, post types that support comments, and alse media/attachments.
443 *
444 * @since 1.0.0
445 */
446 public function hide_comments_column() {
447 $post_types = get_post_types( array(
448 'public' => true,
449 ), 'names' );
450 foreach ( $post_types as $post_type_key => $post_type_name ) {
451 if ( post_type_supports( $post_type_key, 'comments' ) ) {
452 if ( 'attachment' != $post_type_name ) {
453 // For list tables of pages, posts and other post types
454 add_filter( "manage_{$post_type_name}_posts_columns", [$this, 'remove_comment_column'] );
455 } else {
456 // For list table of media/attachment
457 add_filter( 'manage_media_columns', [$this, 'remove_comment_column'] );
458 }
459 }
460 }
461 }
462
463 /**
464 * Add a column called ID
465 *
466 * @param mixed $columns
467 * @return void
468 * @since 1.0.0
469 */
470 public function remove_comment_column( $columns ) {
471 unset($columns['comments']);
472 return $columns;
473 }
474
475 /**
476 * Hide tags column in list tables for posts.
477 *
478 * @since 1.0.0
479 */
480 public function hide_post_tags_column() {
481 $post_types = get_post_types( array(
482 'public' => true,
483 ), 'names' );
484 foreach ( $post_types as $post_type_key => $post_type_name ) {
485 if ( $post_type_name == 'post' ) {
486 add_filter( "manage_posts_columns", [$this, 'remove_post_tags_column'] );
487 }
488 }
489 }
490
491 /**
492 * Add a column called ID
493 *
494 * @param mixed $columns
495 * @return void
496 * @since 1.0.0
497 */
498 public function remove_post_tags_column( $columns ) {
499 unset($columns['tags']);
500 return $columns;
501 }
502
503 }
504