Opened 21 months ago

Closed 20 months ago

Last modified 20 months ago

#18516 closed enhancement (fixed)

Add custom class to WP_Posts_List_Table->single_row() output

Reported by: brandondove Owned by: westi
Priority: normal Milestone: 3.3
Component: General Version: 3.3
Severity: normal Keywords: westi-likes has-patch
Cc: brandondove, jbrown510@…, anointed

Description

I am working on a custom post type implemention with some common custom meta information that I want to display in the post list. There is a need to indicate each post's status with a quick visual queue. Since there is no way to target a group of table rows that have certain characteristics, I resorted to highlighting the rows using jQuery.

Looking at the WP_Posts_List_Table class, it seems that this would be an easy problem to solve by simply adding a filter to the table row class list. I'm sure this same concept could also be extended to the other subclasses of WP_List_Table.

Attachments (3)

18516.diff (1.1 KB) - added by brandondove 21 months ago.
18516.2.diff (1.9 KB) - added by brandondove 21 months ago.
New patch based on feedback from nacin
test-wp-posts-list-table-patch.php (1.5 KB) - added by brandondove 21 months ago.
A simple plugin that adds a custom class to the single row on the post edit screen

Download all attachments as: .zip

Change History (14)

  • Keywords has-patch added
  • Cc brandondove added
  • Owner changed from brandondove to westi
  • Status changed from new to reviewing
  • Cc jbrown510@… added

comment:5 follow-up: ↓ 7   nacin21 months ago

It'd probably make sense for us to use post_class() here.

New patch based on feedback from nacin

A simple plugin that adds a custom class to the single row on the post edit screen

The new patch uses get_post_class for WP_Posts_List_Table as nacin suggested. Duplicated classes on the table row were removed and author-(self|other) was moved into get_post_class for consistency.

comment:7 in reply to: ↑ 5   westi21 months ago

Replying to nacin:

It'd probably make sense for us to use post_class() here.

I'm sure I wrote this comment when I accepted the ticket ;)

  • Keywords westi-likes added
  • Milestone changed from Awaiting Review to 3.3

We should keep the code out of get_post_class(), and instead pass in that value to get_post_class(), which takes an additional classes argument.

  • Resolution set to fixed
  • Status changed from reviewing to closed

In [18706]:

Use get_post_class() in the posts list table. props brandondove, fixes #18516.

  • Cc anointed added
Note: See TracTickets for help on using tickets.