Opened 8 years ago
Closed 8 years ago
#38765 closed defect (bug) (fixed)
Argument in registered_taxonomy hook is lost.
Reported by: | Toro_Unit | Owned by: | swissspidy |
---|---|---|---|
Milestone: | 4.7 | Priority: | normal |
Severity: | normal | Version: | 4.7 |
Component: | Taxonomy | Keywords: | has-patch commit |
Focuses: | docs | Cc: |
Description
$args in register_taxonomy is passed to registered_taxonomy hook without being processed.
Default parameters are missing.
This change breaks compatibility.
Attachments (9)
Change History (29)
#1
@
8 years ago
- Keywords needs-patch added
- Milestone changed from Awaiting Review to 4.7
- Owner set to swissspidy
- Status changed from new to assigned
#2
@
8 years ago
- Focuses docs added
- Keywords has-patch added; needs-patch removed
Note: The dev-note would need to be adjusted accordingly.
#3
@
8 years ago
- Summary changed from Arugment in registered_taxonomy hook is lost. to Argument in registered_taxonomy hook is lost.
#4
@
8 years ago
@swissspidy
I also agree with your idea.
Plugin developers need to implement the code.
<?php add_action( 'registered_taxonomy', 'my_registered_taxonomy', 10, 3 ); function my_registered_taxonomy( $taxonomy, $object_type, $args ) { $args = (array) $args; /* for Compatibility */ /* code... */ }
What do you think about compatibility breaking?
#6
@
8 years ago
What do you think about compatibility breaking?
That's why we announce such changes on make/core and change inline documentation appropriately.
#7
@
8 years ago
For the registered_post_type
hook, we could easily do this because $args
was already an object there. That's not the case for registered_taxonomy
. What we could do:
1) Replace $args
with WP_Taxonomy
, add to dev-note
2) Cast the taxonomy object to an array
3) Implement the ArrayAccess
interface in WP_Taxonomy
@boonebgorges As you have reviewed #36224 previously, what's your take on this?
#8
follow-up:
↓ 9
@
8 years ago
@swissspidy
If implement the ArrayAccess interface in WP_Taxonomy, should WP_Post_Type do the same ?
#9
in reply to:
↑ 8
@
8 years ago
Replying to Toro_Unit:
@swissspidy
If implement the ArrayAccess interface in WP_Taxonomy, should WP_Post_Type do the same ?
There's no need for WP_Post_Type
to implement this interface. And if there is one, it should be handled in a separate ticket. But let's first talk about possible options before going into details for specific solutions.
#10
@
8 years ago
Replying to @swissspidy :
All right.
About backwards compatibility, I found a helpful comment.
#11
@
8 years ago
ArrayAccess
knocks out the use of array_merge()
and a bunch of other array functionality. As that's the raison d'etre for $args
arrays, I'm hesitant to do anything other than cast to an array before passing to the filter. The backcompat implications are too big.
#12
@
8 years ago
@peterwilsoncc Thanks for weighing in! Considering that we're so close to RC, cast to an array seems like the safest approach.
#13
@
8 years ago
In 38765.6.diff:
- makes the arguments used to register the taxonomy available as a property
- passed arguments property to the
registered_taxonomy
hook
Made the args a property to avoid the need to recursively cast to an array.
diff of 4.6.1 arguments and 4.7 arguments passed to the hook.
#14
@
8 years ago
38765.6.diff seems fine to me.
#15
@
8 years ago
In 38765.7.diff, returns $args['name']
which I'd missed in .6
.
#16
@
8 years ago
38765.8.diff now without test code.
#17
@
8 years ago
It seems like there are a few failing tests with 38765.8.diff.
Hey there,
Thanks a ton for your report!
Like in
register_post_type()
we should pass an un-casted$taxonomy_object
(of typeWP_Taxonomy
) to the filter instead.Introduced in #36224 / [38747].