Opened 10 years ago
Closed 9 years ago
#29881 closed task (blessed) (fixed)
Better abstraction for WP_*_List_Table so they are easier to subclass
Reported by: | joehoyle | Owned by: | wonderboymusic |
---|---|---|---|
Milestone: | 4.3 | Priority: | normal |
Severity: | normal | Version: | 3.1 |
Component: | Administration | Keywords: | has-patch |
Focuses: | administration | Cc: |
Description
Currently WP_Posts_List_Table
is a bit of a complicated mess as all columns are in a big switch statement in the single_row()
method. This annoying for a couple of reasons.
- The code is a messy, huge method making it difficult to maintain and understand.
- Subclassing is a pain as you can't override a single column the way the magic method calling of
column_$column_name
should work. - Subclasses don't automatically get the
column_$column_name
functionality asWP_Posts_List_Table
(for whatever reason) closes out this functionality by overriding thesingle_row()
method.
I'm not a fan of changing things for the sake of it, but I think this is an important cleanup. WP_Comment_List_Table
is pretty well implemented in comparison, but I imagine WP_Posts_List_Table
is the most often subclassed due to the heavy use of custom post types.
Apologies if this has been discussed before and/or rejected. I tried to use search... which I seem to kind of fail at finding tickets.
I attached a preliminary path that is functional but needs a couple of edge cases cleaned up. It basically splits out all the columns into their own method which are automatically called from single_row_columns()
.
Attachments (6)
Change History (43)
#2
follow-up:
↓ 22
@
10 years ago
column_taxonomy() should probably be protected. Also, it should probably have a name other than column_ because it could otherwise be invoked by single_row_columns().
Agreed, I did originally have this as private, but then moved to public for other to use it - though I think realistically it's only subclasses that will use it so protected it good. As for naming, it's a workaround for avoiding accidental calling via single_row_columns
so though as much as I hate underscored methods, protected function _column_taxonomy
might make the most sense here. get_taxonomy_column
doesn't follow as it outputs data, output_taxonomy_column
-- perhaps.
#3
@
10 years ago
Refreshed patch against trunk (some fun that was!) and fixed up the naming of the taxonomy helper function to protected output_taxonomy_column()
.
Also provided backwards compat for class names on the post title column; this required overriding single_row_columns()
to set the post title classes, as there is no other way to inject those old classes unless we changed wp-post-list-table.php
to somehow allow filtering / changing of the <td>
class names.
Also fixed up remaining todos in the patch.
#5
@
10 years ago
- Keywords needs-testing 4.2-early added
- Milestone changed from 4.1 to Future Release
#10
@
10 years ago
I tried to refresh this quickly to help out, but it's a bit if a mess at the moment due to churn
This ticket was mentioned in Slack in #core by drew. View the logs.
10 years ago
#12
@
10 years ago
- Keywords 4.3-early added; 4.2-early removed
- Milestone changed from 4.2 to Future Release
Sounds like the patch still needs a refresh, and it's definitely too late for this in 4.2 as we head into beta. Let's try 4.3-early.
#13
@
10 years ago
To try get this ticket on track, or closed out as invalid I'd like to get some discussion going here if this is a favored patch broadly speaking. It appeared initially that it was favored (@nacin chimed in here) - however based off the Slack discussion:
Drew:
Patch is borked and I’m not sure we want to do this right before beta.
azaoz:
uh, the best abstraction for that is... change to UL LI
helen:
help was offered, need was expressed, help was not given. punt.
[in relation to shipping in 4.2)
Some good advice from Mark, Helen and John at WC London: get the go-head and decide on a solution before writing any code. Clearly I made the wrong choice by starting with the code here! I really don't want to refresh this patch (and take a chunk of time) without there being a consensus that this is a good idea.
There's a couple of comments on this ticket mentioning the patch needs a refresh, but based off the initial patch and reception - what this doesn't need is a refreshed patch, it needs a decision if this will be adopted for r+ or decided against. I think the attached patch sufficiently expresses what I wanted to do with this abstraction - we should be talking about whether it's a good or bad idea, not requiring a clean merge-able patch before we can talk about if the idea is a good or bad one.
So, I'd like to open up discussion if anyone wants to weigh in here. Once we have direction, I'm happy to handle a clean patch if that's decided.
This ticket was mentioned in Slack in #core by drew. View the logs.
10 years ago
#16
@
9 years ago
- Keywords needs-testing needs-refresh removed
29881.diff refreshes all of this and makes single_row()
about 1,000,000 times cleaner.
#22
in reply to:
↑ 2
@
9 years ago
- Summary changed from Better abstraction for WP_Posts_List_Table so it's easier to subclass to Better abstraction for WP_*_List_Table so they are easier to subclass
#24
@
9 years ago
WP_Comments_List_Table
and WP_Post_Comments_List_Table
already implement this properly
#29
@
9 years ago
I've attached a patch which is a potential solution to repeating all of single_row_columns()'s code several times.
This ticket was mentioned in Slack in #core by obenland. View the logs.
9 years ago
#33
follow-up:
↓ 34
@
9 years ago
- Owner changed from nacin to wonderboymusic
- Type changed from enhancement to task (blessed)
I'm gonna finish this - just want to make sure the method invocation for special fields isn't weird
#34
in reply to:
↑ 33
@
9 years ago
Replying to wonderboymusic:
I'm gonna finish this - just want to make sure the method invocation for special fields isn't weird
What is left to do to get this finished?
I absolutely love this.
Sadly the list tables were all implemented in slightly different ways, which is probably why we all hate them so much. But there *is* something to salvage here, and single_row_columns() can help with that. It's a nice abstraction we should be using everywhere.
column_taxonomy() should probably be protected. Also, it should probably have a name other than column_ because it could otherwise be invoked by single_row_columns().
I see no back compat concerns here, either.