Opened 14 months ago
Last modified 7 weeks ago
#58824 new enhancement
Add a filter to change the classes in posts list table in admin
Reported by: | zahardoc | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | |
Component: | General | Keywords: | good-first-bug has-patch |
Focuses: | ui, css, administration | Cc: |
Description
Currently, there is no way to change the classes in the posts list table, and the posts list table template is hardcoded. So there is no way to add any classes, for example, specific classes for custom post types there.
Proposal:
Add a filter to "WP_List_Table::get_table_classes()" function, like this:
<?php return apply_filters( 'post_list_table_classes', array( 'widefat', 'fixed', 'striped', $mode_class, $this->_args['plural'] ), $this );
Attachments (2)
Change History (12)
This ticket was mentioned in PR #4885 on WordPress/wordpress-develop by @pamprn.
14 months ago
#2
- Keywords has-patch added
This ticket was mentioned in PR #6299 on WordPress/wordpress-develop by djpbateman.
6 months ago
#3
Added filter and an array checker for safety.
This ticket was mentioned in PR #6799 on WordPress/wordpress-develop by draqo666.
3 months ago
#4
Added filter for WP_List_Table classes.
Trac ticket: (https://core.trac.wordpress.org/ticket/58824)
This ticket was mentioned in PR #6800 on WordPress/wordpress-develop by @thehercules.
3 months ago
#5
Trac Ticket - https://core.trac.wordpress.org/ticket/58824
This PR addresses the issue where there is no way to change the classes in the posts list table.
Currently, the posts list table template is hardcoded, preventing the addition of any specific classes.
Added new filter wp_list_table_classes
to do the same.
Can use like this -
function add_custom_clases( $classes, $table ) {
$classes[] = 'custom-class';
return $classes;
}
add_filter( 'wp_list_table_classes', 'add_custom_clases', 10, 2 );
#6
@
3 months ago
I've submitted a PR(https://github.com/WordPress/wordpress-develop/pull/6800) for this issue where I added a filter wp_list_table_classes and also sanitized CSS classes using sanitize_html_class.
However, adding filter in the class-wp-list-table
would only affect Tables in Pages like Sites
, which directly use class-wp-list-table. This filter would work perfectly for them. However, if we want to add classes to the Custom Post Table, which uses class-wp-post-list-table(that extends the Parent class), the filter would not take effect. There are also many child classes that extend wp_list_table and then this filter wouldn’t work for them.
Do you have any suggestions on how we can implement this in a way that the filter affects all types of tables?
Looking forward to your feedback!
This ticket was mentioned in PR #7122 on WordPress/wordpress-develop by @iflairwebtechnologies.
7 weeks ago
#7
#8
follow-up:
↓ 9
@
7 weeks ago
@zahardoc
You can review #7122 patch, the changed code with added custom class for custom post type
#9
in reply to:
↑ 8
@
7 weeks ago
Replying to iflairwebtechnologies:
@zahardoc
You can review #7122 patch, the changed code with added custom class for custom post type
@iflairwebtechnologies Are you sure this is the correct link? It leads me to the 16-year-old closed ticket.
Regarding the 58824 patch - is it possible to also add a filter there? Something like this:
<?php return apply_filters( 'wp_list_table_classes', $classes, $this );
Thank you!
#10
@
7 weeks ago
@zahardoc
by mistake selected #7122
You can review, added new patch 58824-1.patch with the updated code
You can use a filter like below in the theme functions.php file and check
function my_custom_list_table_classes( $classes, $list_table ) { // Add a custom class $classes[] = 'my-custom-class'; // Remove a class if needed $key = array_search( 'some-existing-class', $classes ); if ( $key !== false ) { unset( $classes[$key] ); } return $classes; } add_filter( 'wp_list_table_classes', 'my_custom_list_table_classes', 10, 2 );
Trac ticket: https://core.trac.wordpress.org/ticket/58824