Make WordPress Core

Opened 8 years ago

Closed 8 years ago

#38765 closed defect (bug) (fixed)

Argument in registered_taxonomy hook is lost.

Reported by: toro_unit's profile Toro_Unit Owned by: swissspidy's profile 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)

38765.diff (352 bytes) - added by Toro_Unit 8 years ago.
38765.2.diff (1021 bytes) - added by swissspidy 8 years ago.
38765.3.diff (1.7 KB) - added by Toro_Unit 8 years ago.
fix param comments
38765.4.diff (960 bytes) - added by Toro_Unit 8 years ago.
38765.5.diff (2.4 KB) - added by Toro_Unit 8 years ago.
implements ArrayAccess
38765.6.diff (1.4 KB) - added by peterwilsoncc 8 years ago.
38765.7.diff (1.4 KB) - added by peterwilsoncc 8 years ago.
38765.8.diff (1.4 KB) - added by peterwilsoncc 8 years ago.
38765.9.diff (589 bytes) - added by peterwilsoncc 8 years ago.

Download all attachments as: .zip

Change History (29)

@Toro_Unit
8 years ago

#1 @swissspidy
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

Hey there,

Thanks a ton for your report!

Like in register_post_type() we should pass an un-casted $taxonomy_object (of type WP_Taxonomy) to the filter instead.

Introduced in #36224 / [38747].

@swissspidy
8 years ago

#2 @swissspidy
8 years ago

  • Focuses docs added
  • Keywords has-patch added; needs-patch removed

Note: The dev-note would need to be adjusted accordingly.

#3 @swissspidy
8 years ago

  • Summary changed from Arugment in registered_taxonomy hook is lost. to Argument in registered_taxonomy hook is lost.

#4 @Toro_Unit
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?

@Toro_Unit
8 years ago

fix param comments

@Toro_Unit
8 years ago

#5 @Toro_Unit
8 years ago

Sorry 38765.3.diff is a mistake.

#6 @swissspidy
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 @swissspidy
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: @Toro_Unit
8 years ago

@swissspidy

If implement the ArrayAccess interface in WP_Taxonomy, should WP_Post_Type do the same ?

Last edited 8 years ago by Toro_Unit (previous) (diff)

#9 in reply to: ↑ 8 @swissspidy
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.

@Toro_Unit
8 years ago

implements ArrayAccess

#10 @Toro_Unit
8 years ago

Replying to @swissspidy :

All right.

About backwards compatibility, I found a helpful comment.

https://core.trac.wordpress.org/ticket/20103#comment:9

#11 @peterwilsoncc
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 @swissspidy
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 @peterwilsoncc
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 @boonebgorges
8 years ago

38765.6.diff seems fine to me.

#15 @peterwilsoncc
8 years ago

In 38765.7.diff, returns $args['name'] which I'd missed in .6.

Version 0, edited 8 years ago by peterwilsoncc (next)

#16 @peterwilsoncc
8 years ago

38765.8.diff now without test code.

#17 @swissspidy
8 years ago

It seems like there are a few failing tests with 38765.8.diff.

#18 @peterwilsoncc
8 years ago

@swissspidy this passes and i don't know what I was thinking this-morning, labels and caps have been objects fro some time :)

#19 @swissspidy
8 years ago

  • Keywords commit added

#20 @peterwilsoncc
8 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 39283:

Taxonomy: Update register_taxonomy hook to use WP_Taxonomy object.

Casts WP_Taxonomy to an array for passing to the register_taxonomy hook. This maintains backward compatibility with the processed arguments used prior to WordPress 4.7.

Fixes #38765.

Note: See TracTickets for help on using tickets.