Make WordPress Core

Opened 11 months ago

Last modified 4 days ago

#58824 new enhancement

Add a filter to change the classes in posts list table in admin

Reported by: zahardoc's profile 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 );

Change History (6)

#1 @Hareesh Pillai
11 months ago

  • Keywords good-first-bug added

This ticket was mentioned in PR #4885 on WordPress/wordpress-develop by @pamprn.


11 months ago
#2

  • Keywords has-patch added

This ticket was mentioned in PR #6299 on WordPress/wordpress-develop by djpbateman.


3 months ago
#3

Added filter and an array checker for safety.

This ticket was mentioned in PR #6799 on WordPress/wordpress-develop by draqo666.


5 days 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.


4 days 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 @thehercules
4 days 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!

Note: See TracTickets for help on using tickets.