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.6.7.1 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 7 months ago class-admin-menu-organizer.php 7 months ago class-admin-menu-svg-icon-mask.php 7 months ago class-auto-publish-posts-with-missed-schedule.php 7 months ago class-avif-upload.php 7 months ago class-captcha-protection.php 7 months ago class-change-login-url.php 7 months ago class-cleanup-admin-bar.php 7 months ago class-common-methods.php 7 months ago class-content-duplication.php 7 months ago class-content-order.php 7 months ago class-custom-admin-footer-text.php 7 months ago class-custom-body-class.php 7 months ago class-custom-css.php 7 months ago class-custom-nav-menu-items-in-new-tab.php 7 months ago class-deactivation.php 7 months ago class-disable-author-archives.php 7 months ago class-disable-comments.php 7 months ago class-disable-dashboard-widgets.php 7 months ago class-disable-embeds.php 7 months ago class-disable-feeds.php 7 months ago class-disable-gutenberg.php 7 months ago class-disable-rest-api.php 7 months ago class-disable-smaller-components.php 7 months ago class-disable-updates.php 7 months ago class-disable-xml-rpc.php 7 months ago class-display-system-summary.php 7 months ago class-email-address-obfuscator.php 7 months ago class-email-delivery.php 7 months ago class-enhance-list-tables.php 7 months ago class-external-permalinks.php 7 months ago class-heartbeat-control.php 7 months ago class-hide-admin-bar.php 7 months ago class-hide-admin-notices.php 7 months ago class-image-sizes-panel.php 7 months ago class-image-upload-control.php 7 months ago class-insert-head-body-footer-code.php 7 months ago class-last-login-column.php 7 months ago class-limit-login-attempts.php 7 months ago class-login-id-type.php 7 months ago class-login-logout-menu.php 7 months ago class-maintenance-mode.php 7 months ago class-manage-ads-appads-txt.php 7 months ago class-manage-robots-txt.php 7 months ago class-media-replacement.php 7 months ago class-multiple-user-roles.php 7 months ago class-obfuscate-author-slugs.php 7 months ago class-open-external-links-in-new-tab.php 7 months ago class-password-protection.php 7 months ago class-redirect-after-login.php 7 months ago class-redirect-after-logout.php 7 months ago class-redirect-fourofour.php 7 months ago class-registration-date-column.php 7 months ago class-revisions-control.php 7 months ago class-search-engines-visibility.php 7 months ago class-settings-fields-render.php 7 months ago class-settings-sanitization.php 7 months ago class-settings-sections-fields.php 7 months ago class-show-custom-taxonomy-filters.php 7 months ago class-site-identity-on-login-page.php 7 months ago class-svg-upload.php 7 months ago class-various-admin-ui-enhancements.php 7 months ago class-view-admin-as-role.php 7 months ago class-wider-admin-menu.php 7 months ago class-wp-config-transformer.php 7 months ago
class-enhance-list-tables.php
505 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 '<a href="' . get_edit_post_link( $id ) . '">' . get_the_post_thumbnail( $id, $size, '' ) . '</a>';
77 } else {
78 echo '<a href="' . get_edit_post_link( $id ) . '"><img src="' . esc_url( plugins_url( 'assets/img/default_featured_image.jpg', __DIR__ ) ) . '" /></a>';
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 = wp_strip_all_tags( 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_filter(
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 $modified_date_time_unix = strtotime( get_post_field( 'post_modified_gmt', $id ) );
193 echo '<span class="last-modified-timestamp">' . wp_date( get_option( 'date_format' ), $modified_date_time_unix ) . '<br />' . wp_date( get_option( 'time_format' ), $modified_date_time_unix ) . '</span>';
194 }
195 }
196
197 /**
198 * Make last modified column sortable
199 *
200 * @since 7.4.0
201 */
202 public function make_last_modified_column_sortable( $columns ) {
203 $columns['asenha-last-modified'] = 'modified';
204 return $columns;
205 }
206
207 /**
208 * Add ID column list table of pages, posts, custom post types, media, taxonomies, custom taxonomies, users amd comments
209 *
210 * @since 1.0.0
211 */
212 public function show_id_column() {
213 // For pages and hierarchical post types list table
214 add_filter( 'manage_pages_columns', [$this, 'add_id_column'] );
215 add_action(
216 'manage_pages_custom_column',
217 [$this, 'add_id_echo_value'],
218 10,
219 2
220 );
221 // For posts and non-hierarchical custom posts list table
222 add_filter( 'manage_posts_columns', [$this, 'add_id_column'] );
223 add_action(
224 'manage_posts_custom_column',
225 [$this, 'add_id_echo_value'],
226 10,
227 2
228 );
229 // For media list table
230 add_filter( 'manage_media_columns', [$this, 'add_id_column'] );
231 add_action(
232 'manage_media_custom_column',
233 [$this, 'add_id_echo_value'],
234 10,
235 2
236 );
237 // For list table of all taxonomies
238 $taxonomies = get_taxonomies( [
239 'public' => true,
240 ], 'names' );
241 foreach ( $taxonomies as $taxonomy ) {
242 add_filter( 'manage_edit-' . $taxonomy . '_columns', [$this, 'add_id_column'] );
243 add_action(
244 'manage_' . $taxonomy . '_custom_column',
245 [$this, 'add_id_return_value'],
246 10,
247 3
248 );
249 }
250 // For users list table
251 add_filter( 'manage_users_columns', [$this, 'add_id_column'] );
252 add_action(
253 'manage_users_custom_column',
254 [$this, 'add_id_return_value'],
255 10,
256 3
257 );
258 // For comments list table
259 add_filter( 'manage_edit-comments_columns', [$this, 'add_id_column'] );
260 add_action(
261 'manage_comments_custom_column',
262 [$this, 'add_id_echo_value'],
263 10,
264 3
265 );
266 }
267
268 /**
269 * Add a column called ID
270 *
271 * @param mixed $columns
272 * @return void
273 * @since 1.0.0
274 */
275 public function add_id_column( $columns ) {
276 $columns['asenha-id'] = 'ID';
277 return $columns;
278 }
279
280 /**
281 * Echo post ID value to a column
282 *
283 * @param mixed $column_name
284 * @param mixed $id
285 * @since 1.0.0
286 */
287 public function add_id_echo_value( $column_name, $id ) {
288 if ( 'asenha-id' === $column_name ) {
289 echo esc_html( $id );
290 }
291 }
292
293 /**
294 * Return post ID value to a column
295 *
296 * @param mixed $value
297 * @param mixed $column_name
298 * @param mixed $id
299 * @since 1.0.0
300 */
301 public function add_id_return_value( $value, $column_name, $id ) {
302 if ( 'asenha-id' === $column_name ) {
303 $value = $id;
304 }
305 return $value;
306 }
307
308 /**
309 * Add file size column to media library
310 *
311 * @since 6.9.5
312 */
313 public function add_column_file_size( $columns ) {
314 $columns['asenha-file-size'] = __( 'File Size', 'admin-site-enhancements' );
315 return $columns;
316 }
317
318 /**
319 * Display the file size value
320 *
321 * @since 6.9.5
322 */
323 public function display_file_size( $column_name, $attachment_id ) {
324 if ( 'asenha-file-size' != $column_name ) {
325 return;
326 }
327 $file_size = filesize( get_attached_file( $attachment_id ) );
328 $file_size = size_format( $file_size, 1 );
329 // Show one decimal point
330 echo esc_html( $file_size );
331 }
332
333 /**
334 * Add file size column to media library
335 *
336 * @since 6.9.5
337 */
338 public function add_media_styles() {
339 echo '<style>.column-asenha-file-siz {width: 60px;}</style>';
340 }
341
342 /**
343 * Add ID in the action row of list tables for pages, posts, custom post types, media, taxonomies, custom taxonomies, users amd comments
344 *
345 * @since 4.7.4
346 */
347 public function show_id_in_action_row() {
348 add_filter(
349 'page_row_actions',
350 array($this, 'add_id_in_action_row'),
351 99,
352 2
353 );
354 add_filter(
355 'post_row_actions',
356 array($this, 'add_id_in_action_row'),
357 99,
358 2
359 );
360 add_filter(
361 'cat_row_actions',
362 array($this, 'add_id_in_action_row'),
363 99,
364 2
365 );
366 add_filter(
367 'tag_row_actions',
368 array($this, 'add_id_in_action_row'),
369 99,
370 2
371 );
372 add_filter(
373 'media_row_actions',
374 array($this, 'add_id_in_action_row'),
375 99,
376 2
377 );
378 add_filter(
379 'comment_row_actions',
380 array($this, 'add_id_in_action_row'),
381 99,
382 2
383 );
384 add_filter(
385 'user_row_actions',
386 array($this, 'add_id_in_action_row'),
387 99,
388 2
389 );
390 }
391
392 /**
393 * Output the ID in the action row
394 *
395 * @since 4.7.4
396 */
397 public function add_id_in_action_row( $actions, $object ) {
398 if ( current_user_can( 'edit_posts' ) ) {
399 // For pages, posts, custom post types, media/attachments, users
400 if ( property_exists( $object, 'ID' ) ) {
401 $id = $object->ID;
402 }
403 // For taxonomies
404 if ( property_exists( $object, 'term_id' ) ) {
405 $id = $object->term_id;
406 }
407 // For comments
408 if ( property_exists( $object, 'comment_ID' ) ) {
409 $id = $object->comment_ID;
410 }
411 $actions['asenha-list-table-item-id'] = '<span class="asenha-list-table-item-id">ID: ' . $id . '</span>';
412 }
413 return $actions;
414 }
415
416 /**
417 * Show last modified column for pages, posts and CPTs
418 *
419 * @since 7.4.0
420 */
421 public function hide_date_column() {
422 foreach ( get_post_types() as $post_type ) {
423 add_filter(
424 'manage_' . $post_type . '_posts_columns',
425 [$this, 'remove_date_column'],
426 10,
427 1
428 );
429 }
430 }
431
432 /**
433 * Add a column called Last Modified
434 *
435 * @since 7.4.0
436 */
437 public function remove_date_column( $columns ) {
438 unset($columns['date']);
439 return $columns;
440 }
441
442 /**
443 * Hide comments column in list tables for pages, post types that support comments, and alse media/attachments.
444 *
445 * @since 1.0.0
446 */
447 public function hide_comments_column() {
448 $post_types = get_post_types( array(
449 'public' => true,
450 ), 'names' );
451 foreach ( $post_types as $post_type_key => $post_type_name ) {
452 if ( post_type_supports( $post_type_key, 'comments' ) ) {
453 if ( 'attachment' != $post_type_name ) {
454 // For list tables of pages, posts and other post types
455 add_filter( "manage_{$post_type_name}_posts_columns", [$this, 'remove_comment_column'] );
456 } else {
457 // For list table of media/attachment
458 add_filter( 'manage_media_columns', [$this, 'remove_comment_column'] );
459 }
460 }
461 }
462 }
463
464 /**
465 * Add a column called ID
466 *
467 * @param mixed $columns
468 * @return void
469 * @since 1.0.0
470 */
471 public function remove_comment_column( $columns ) {
472 unset($columns['comments']);
473 return $columns;
474 }
475
476 /**
477 * Hide tags column in list tables for posts.
478 *
479 * @since 1.0.0
480 */
481 public function hide_post_tags_column() {
482 $post_types = get_post_types( array(
483 'public' => true,
484 ), 'names' );
485 foreach ( $post_types as $post_type_key => $post_type_name ) {
486 if ( $post_type_name == 'post' ) {
487 add_filter( "manage_posts_columns", [$this, 'remove_post_tags_column'] );
488 }
489 }
490 }
491
492 /**
493 * Add a column called ID
494 *
495 * @param mixed $columns
496 * @return void
497 * @since 1.0.0
498 */
499 public function remove_post_tags_column( $columns ) {
500 unset($columns['tags']);
501 return $columns;
502 }
503
504 }
505