#26948 closed enhancement (fixed)
Filter taxonomies available in quick edit
Reported by: | hlashbrooke | Owned by: | boonebgorges |
---|---|---|---|
Milestone: | 4.2 | Priority: | normal |
Severity: | normal | Version: | 3.8 |
Component: | Taxonomy | Keywords: | has-patch |
Focuses: | ui | Cc: |
Description
There are a number of use cases for hiding a taxonomy from the quick edit panel, but it is currently not possible.
In WP_Posts_List_Table::inline_edit(), the list of available taxonomies for the post type is fetched, but there is no way to modify that list. I propose adding a filter decide which taxonomies will be displayed. Because this is a filter it won't affect any existing functionality and will make the admin UI that much more customisable.
Attachments (6)
Change History (32)
#2
@
11 years ago
- Component changed from Taxonomy to Quick/Bulk Edit
Thanks for the patch! I definitely like the idea of being able to keep a taxonomy out of quick edit, especially given that we have better default support for custom taxonomy meta boxes now. If we go the filter route, I think it would probably make more sense to filter the entire array of $taxonomy_names
right from the get go rather than within the foreach
.
That said, I wonder if we should look into another arg in register_taxonomy()
. If not that, maybe we should have the meta_box_cb
arg make a smart initial decision in addition to a filter.
Also, big picture, quick/inline edit needs some love all around.
#3
@
11 years ago
I agree that the whole thing needs some general love for sure, so if this patch doesn't fit into the bigger picture for quick edit then I'm happy to drop it.
My original idea was to filter the taxonomy array, but each element of the array is an object, which meant the filter received an array of taxonomy objects making it slightly more complicated to filter. There would be a similar problem with $taxonomy_names
- it returns an array of names with a numeric index, so in order to filter the list you would need to loop through the array or use array_search()
or something similar. By doing it in the foreach
it means your filter function simply needs a quick conditional and a boolean result, which is much friendly for the end-user I think.
Adding a 'quick_edit' => true
type of argument to register_taxonomy()
might be a better option - I had considered that, but thought of going for a less intrusive approach for the first pass.
I'm open to any thoughts/suggestions :)
#4
@
11 years ago
+1 for adding an argument to register_taxonomy()
. @hlashbrooke care to give a second patch a go? :)
#6
follow-up:
↓ 7
@
11 years ago
New diff attached - it adds a quick_edit
argument to the register_taxonomy()
function, which is set to true
by default. Then it checks that parameter in WP_Posts_List_Table::inline_edit()
when it displays the quick/bulk edit panel.
#7
in reply to:
↑ 6
;
follow-up:
↓ 8
@
11 years ago
Replying to hlashbrooke:
New diff attached - it adds a
quick_edit
argument to theregister_taxonomy()
function, which is set totrue
by default. Then it checks that parameter inWP_Posts_List_Table::inline_edit()
when it displays the quick/bulk edit panel.
Nice. Had you considered defaulting quick_edit
to null, similarly to how the show_in_*
options are? Possibly even using show_in_quick_edit
instead?
Setting those args null by default allows a sort of predictable fallback to the value of show_ui
which falls back to the value of public
. Just seems to fit a bit more logically with the show_ui
group of arguments than standing it alone. Thoughts?
#8
in reply to:
↑ 7
@
11 years ago
Replying to DrewAPicture:
Replying to hlashbrooke:
New diff attached - it adds a
quick_edit
argument to theregister_taxonomy()
function, which is set totrue
by default. Then it checks that parameter inWP_Posts_List_Table::inline_edit()
when it displays the quick/bulk edit panel.
Nice. Had you considered defaulting
quick_edit
to null, similarly to how theshow_in_*
options are? Possibly even usingshow_in_quick_edit
instead?
Setting those args null by default allows a sort of predictable fallback to the value of
show_ui
which falls back to the value ofpublic
. Just seems to fit a bit more logically with theshow_ui
group of arguments than standing it alone. Thoughts?
Done :)
Good point about the show_ui
fallback - that hadn't occurred to me.
#9
@
11 years ago
taxonomy_quick_edit2.diff looks pretty good. Now that you've got show_in_quick_edit
defaulting back to to the value of show_ui
, you can just check it by itself in the list table foreach:
<?php if ( ! $taxonomy->show_in_quick_edit ) { continue; }
You'll also need to add a line or two description to the register_taxonomy()
phpdoc block explaining about show_in_quick_edit
.
#10
@
11 years ago
- Component changed from Quick/Bulk Edit to Taxonomy
Moving this to Taxonomy as the focus has shifted to register_taxonomy().
Is it possible you want a taxonomy to be assigned to multiple post types but only appear in one situation? I think a filter is *also* warranted.
#11
@
11 years ago
@DrewAPicture I improved the use in WP_Posts_List_Table::inline_edit()
and added the docblock comment, so that should be all set now.
Thanks @nacin - I agree that having a filter as well would help, so I added that back in. The flow now would be to set show_in_quick_edit
to true
for the taxonomy and then hide per post type using the quick_edit_show_taxonomy
filter that accepts 2 parameters (taxonomy name and post type label) and should return boolean true/false. I'm happy to change that order if you think a different way would flow more smoothly.
#13
@
10 years ago
+1 for the filter in the quick edit! My plugin, Radio Buttons for Taxonomies, has to hack into the global $wp_taxonomies variable to prevent taxonomies from showing up in the quick edit.. and it is janky and prone to error. A filter would help immensely. Something like:
$taxonomy_names = apply_filters( 'quick_edit_taxonomies', get_object_taxonomies( $screen->post_type ), $screen->post_type );
in class-wp-posts-list-table.php function inline_edit(). I'd make a patch, but since trying to get the git mirrors working on my local setup, my git app has blown a gasket.
#14
follow-up:
↓ 15
@
10 years ago
While trying to find this ticket again tonight, it turns out that it is a duplicate of my old ticket: https://core.trac.wordpress.org/ticket/21840 I guess that's why it seemed to familiar! :)
I still really want this.. and I attached a patch in the other thread.
#15
in reply to:
↑ 14
@
10 years ago
Replying to helgatheviking:
While trying to find this ticket again tonight, it turns out that it is a duplicate of my old ticket: https://core.trac.wordpress.org/ticket/21840 I guess that's why it seemed to familiar! :)
I still really want this.. and I attached a patch in the other thread.
Glad there's some more support for this - my patch here includes a filter like that as well as a new parameter for register_taxonomy()
that will decide whether or not a taxonomy should show in the quick edit panel.
#17
@
10 years ago
- Milestone changed from Awaiting Review to 4.2
Looks good to me. I'm going to clean up the documentation and code style a little bit. Then let's do this.
#18
@
10 years ago
- Owner set to boonebgorges
- Resolution set to fixed
- Status changed from new to closed
In 31307:
@
10 years ago
Do not update taxonomy on 'inline-save' ajax action when 'show_in_quick_edit' is set to false
#20
@
10 years ago
Above patch disables also updating taxonomy on inline-save
ajax action when show_in_quick_edit
is set to false
#22
@
10 years ago
So what's the next step here - @meloniq's additional patch is solid, so can it all be merged in from there? Or do you need a single patch that contains all the updates?
#23
@
10 years ago
26948-inline-save.patch needs a duplicate hook comment (/** This filter is documented in ... */
).
#24
@
10 years ago
The goal of [26948-inline-save.patch] is to block direct POST requests from saving forbidden taxonomy terms during the Quick Edit save routine. So I think the best place to put the block is in the Quick Edit save routine itself: wp_ajax_inline_save()
. Fix coming up, with a unit test.
So what's the next step here - @meloniq's additional patch is solid, so can it all be merged in from there? Or do you need a single patch that contains all the updates?
The initial stuff was committed in [31308], so no need for more patches.
First pass at class-wp-posts-list-table.php