Opened 15 years ago
Closed 13 years ago
#18166 closed enhancement (fixed)
Be able to amend the parent dropdown on the edit taxonomy term page
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 3.7 | Priority: | normal |
| Severity: | normal | Version: | 3.2.1 |
| Component: | Taxonomy | Keywords: | has-patch |
| Focuses: | Cc: |
Description
It would be useful to filter the parent dropdown on the edit taxonomy term page (/wp-admin/edit-tags.php?taxonomy=foo&post_type=bar).
See attached patch (The filter probably needs a better name, but you get the point).
Attachments (3)
Change History (16)
#1
@
15 years ago
- Summary changed from Would be nice to be able to amend the parent dropdown on the edit taxonomy term page to Be able to amend the parent dropdown on the edit taxonomy term page
apply_filters() only returns one value, so you need to pass the entire array in the first argument for it to be returned.
#2
follow-up:
↓ 3
@
15 years ago
Actually - the patch is exactly what I need, I think perhaps the description I used is misleading.
I want to be able to amend the arguments passed to wp_dropdown_categories. In the use case that led to me reporting this I'm amending the depth parameter so that the end result is that the dropdown list only contains top-level items.
So while my use-case is to cause the contents of the drop-down to be amended, I'm not actually looking to filter the output directly ...
#3
in reply to:
↑ 2
@
15 years ago
Replying to leewillis77:
Actually - the patch is exactly what I need, I think perhaps the description I used is misleading.
I want to be able to amend the arguments passed to wp_dropdown_categories. In the use case that led to me reporting this I'm amending the depth parameter so that the end result is that the dropdown list only contains top-level items.
So while my use-case is to cause the contents of the drop-down to be amended, I'm not actually looking to filter the output directly ...
Slightly bad wording on my part, the issue is that with your patch the only value eventually passed to wp_dropdown_categories() is $taxonomy (after filtering) since the first value passed to apply_filters() is the one being filtered. You need to be passing the entire arguments array as the first parameter. Also please make patches relative to the root directory.
#4
@
15 years ago
Ah, right OK. The value returned is up to the filter function itself. In my working example I was doing:
function ($a, $b) {
modify_b();
return $b;
}
But you're right - as a matter of style I guess the arguments should be the other way around, so that the first variable passed is the one that is "filtered". Re-worked patch attached.
#5
@
15 years ago
But you're right - as a matter of style I guess the arguments should be the other way around, so that the first variable passed is the one that is "filtered".
It's not just a matter of style, In the event there's nothing hooked to the filter, the first arg would be returned. So if nothing was using the filter in the original patch, $taxonomy would've been passed to wp_dropdown_categories() instead of the array.
#7
@
14 years ago
I'm still having to work-around (Bodge) the lack of this filter - is there anything else I can to hasten its inclusion? The patch still applies cleanly to trunk for info.
#8
@
13 years ago
- Keywords needs-patch added; has-patch removed
Seems like the filter should be called taxonomy_parent_dropdown instead of taxonomy_dropdown_args which seems to refer to any ol' wp_dropdown_categories
#10
follow-up:
↓ 11
@
13 years ago
- Milestone changed from Awaiting Review to 3.7
$taxonomy is passed as a part of the array, so passing it again as a second argument appears to be redundant.
#11
in reply to:
↑ 10
;
follow-up:
↓ 12
@
13 years ago
Replying to SergeyBiryukov:
$taxonomyis passed as a part of the array, so passing it again as a second argument appears to be redundant.
Not necessarily — an earlier filter could change the 'taxonomy' key, rendering the context incorrect. The alternative would be to force 'taxonomy' => $taxonomy after the filter.
We can probably clean this up a bit, stylistically — break this out into a few lines of code.
#12
in reply to:
↑ 11
@
13 years ago
Replying to nacin:
We can probably clean this up a bit, stylistically — break this out into a few lines of code.
Something like this?
<?php if ( is_taxonomy_hierarchical( $taxonomy ) ) : $dropdown_args = array( 'hide_empty' => 0, 'hide_if_empty' => false, 'taxonomy' => $taxonomy, 'name' => 'parent', 'orderby' => 'name', 'hierarchical' => true, 'show_option_none' => __( 'None' ) ); ?> <div class="form-field"> <label for="parent"><?php _ex('Parent', 'Taxonomy Parent'); ?></label> <?php wp_dropdown_categories( apply_filters ( 'taxonomy_parent_dropdown_args', $dropdown_args ), $taxonomy ); ?>
Not sure I follow forcing 'taxonomy' => $taxonomy after the filter.
Example filter