Make WordPress Core

Opened 20 months ago

Last modified 2 months ago

#25408 new enhancement

Ability to specify that a list table column is "primary"

Reported by: helen Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version:
Component: Administration Keywords: has-patch needs-testing 4.1-early
Focuses: Cc:


List tables have a "primary" column of sorts; that is, the one with the row actions. We should be able to specify which column is the primary one via API, apply an appropriate class, and display the row actions in cells in that column. Currently, developers customizing the list table columns often need to re-create row actions if they do not use the post name column, or just live with the row actions appearing in a less sensible spot.

This thought stems from three things in particular:

  1. The above customization example.
  2. Old experiments (nearly exactly 2 years ago) in making list tables responsive: http://cl.ly/3F1L0N3z1M0F0Z3t0X3W in #18198.
  3. The assortment of selectors in [25595] that are not particularly robust and not easily reused by developers. We should be able to target something like .has-row-actions instead.

Attachments (3)

25408.diff (46.1 KB) - added by DaveAl 19 months ago.
25408.2.diff (49.5 KB) - added by DaveAl 19 months ago.
25408.3.diff (57.8 KB) - added by jesin 13 months ago.
Modified 25408.2.diff based on WordPress 4.0-alpha

Download all attachments as: .zip

Change History (16)

comment:1 @helen20 months ago

  • Milestone changed from Awaiting Review to 3.7

Putting in 3.7 especially to address point 3 - if not done extremely soon, we should punt it again.

comment:2 @helen20 months ago

  • Type changed from enhancement to task (blessed)

comment:3 @DaveAl19 months ago

Ok, I see I've misread the requirements. In any case, I've rectified that situation and attached a patch. Feedback is appreciated.

I made some mistakes in the first attachment, so please ignore it and use the second one .

In essence:
I've added two new methods to class WP_List_Table, both intended to be over-ridden, but not abstract:

  1. get_primary_column(): Takes no arguments, returns the name of the desired primary column. Hardcoded much the same way as get_columns, but just one string.
  2. handle_actions( $item, $column_name, $primary ): Takes three arguments: the item - whether post, user, comment, etc. - the current column_name, and the name of the primary column. If the column name matches the primary, then the function returns the actions to be displayed.

I've also modified the various list tables that display row actions to use this new functionality. Some have single_row over-ridden, some don't. Some override the row_actions function, others just directly created and displayed their row actions in the default primary. The latter ones are where I extracted that code to override handle_actions.

The only one I didn't touch was class-wp-links-list-table.php because I don't have the links manager plugin to test it with yet, so I left that one alone.

Here's a list of the files I modified, which will now have the class "has-row-actions" in the primary cells.

Last edited 19 months ago by DaveAl (previous) (diff)

comment:4 @johnbillion19 months ago

  • Keywords needs-patch added
  • Milestone changed from 3.7 to Future Release

@DaveAl19 months ago

@DaveAl19 months ago

comment:5 @DaveAl19 months ago

  • Keywords has-patch needs-testing added; needs-patch removed

comment:6 @helen13 months ago

Related: #28011, #26302.

Putting into 4.0 - this will simplify a lot of things in JS and responsive CSS, make accessibility better, and enhance developer happiness. Will review patch, unless somebody beats me to it.

comment:7 @jesin13 months ago

  • Keywords needs-refresh added; has-patch needs-testing removed

By looking at the patch and the current file I can say that the line numbers have changed a lot since the patch was uploaded. The code in the original files have changed too.

comment:8 @samuelsidler13 months ago

  • Milestone changed from Future Release to 4.0

@jesin13 months ago

Modified 25408.2.diff based on WordPress 4.0-alpha

comment:9 @jesin13 months ago

  • Keywords has-patch needs-testing added; needs-refresh removed

comment:10 @helen10 months ago

  • Type changed from task (blessed) to enhancement

A lot going on in the patch, late for 4.0 (as much as obviously I want this). Patch seems to be heading in a good direction. One thing I'm noticing is setting HTML classes - should append to the set if primary column, rather than if/else, so it's easier to follow. Places where it's echoed inline should probably be set to a variable first for clarity as well.

comment:11 @helen10 months ago

  • Keywords 4.1-early added
  • Milestone changed from 4.0 to Future Release

comment:12 @ircbot9 months ago

This ticket was mentioned in IRC in #wordpress-dev by helen. View the logs.

comment:13 @jeremyfelt2 months ago

In 31674:

Reveal row actions on focus in the network users list table.

In the future, we'll re-factor this selector pile in a way that makes things cleaner. See #25408.

Props afercia.

Fixes #31003.

Note: See TracTickets for help on using tickets.