Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions src/wp-admin/includes/class-wp-posts-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -640,12 +640,24 @@ protected function get_table_classes() {

$mode_class = esc_attr( 'table-view-' . $mode );

return array(
'widefat',
'fixed',
'striped',
$mode_class,
is_post_type_hierarchical( $this->screen->post_type ) ? 'pages' : 'posts',
/**
* Filters the CSS classes applied to the posts list table.
*
* @since 6.8.0
*
* @param string[] $classes An array of CSS classes for the posts list table.
* @param string $post_type The post type slug.
*/
return apply_filters(
'post_list_table_classes',
array(
'widefat',
'fixed',
'striped',
$mode_class,
is_post_type_hierarchical( $this->screen->post_type ) ? 'pages' : 'posts',
),
$this->screen->post_type
);
}

Expand Down
65 changes: 65 additions & 0 deletions tests/phpunit/tests/admin/wpPostsListTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,71 @@ public function test_empty_trash_button_should_not_be_shown_if_there_are_no_post
$this->assertStringNotContainsString( 'id="delete_all"', $output );
}

/**
* @ticket 58824
*
* @covers WP_Posts_List_Table::get_table_classes
*/
public function test_get_table_classes_returns_default_classes() {
$method = new ReflectionMethod( $this->table, 'get_table_classes' );

$classes = $method->invoke( $this->table );

$this->assertContains( 'widefat', $classes );
$this->assertContains( 'fixed', $classes );
$this->assertContains( 'striped', $classes );
$this->assertContains( 'pages', $classes );
}

/**
* @ticket 58824
*
* @covers WP_Posts_List_Table::get_table_classes
*/
public function test_get_table_classes_filter_modifies_classes() {
add_filter(
'post_list_table_classes',
static function ( $classes ) {
$classes[] = 'my-custom-class';
return $classes;
}
);

$method = new ReflectionMethod( $this->table, 'get_table_classes' );

$classes = $method->invoke( $this->table );

remove_all_filters( 'post_list_table_classes' );

$this->assertContains( 'my-custom-class', $classes );
}

/**
* @ticket 58824
*
* @covers WP_Posts_List_Table::get_table_classes
*/
public function test_get_table_classes_filter_receives_post_type() {
$received_post_type = null;

add_filter(
'post_list_table_classes',
static function ( $classes, $post_type ) use ( &$received_post_type ) {
$received_post_type = $post_type;
return $classes;
},
10,
2
);

$method = new ReflectionMethod( $this->table, 'get_table_classes' );
$method->invoke( $this->table );

remove_all_filters( 'post_list_table_classes' );

$this->assertSame( 'page', $received_post_type );
}

/**
* @ticket 42066
*
Expand Down
Loading