Make WordPress Core

Opened 7 years ago

Closed 7 years ago

#39215 closed defect (bug) (fixed)

Support for string $args in wp_get_object_terms() broken in 4.7

Reported by: sstoqnov's profile sstoqnov Owned by: dd32's profile dd32
Milestone: 4.7.1 Priority: normal
Severity: critical Version: 4.7
Component: Taxonomy Keywords: has-patch has-unit-tests fixed-major
Focuses: Cc:

Description (last modified by ocean90)

It appears that wp_get_object_terms() no longer supports the string version of the $args parameter. Prior to WordPress 4.7 it used to support both string and array values, and there might be multiple plugins and themes that rely on this fact. It's also documented as string|array in the Codex.

After digging a bit I found that this regression has been introduced in [38667] which removed a lot of redundant code.

Attachments (4)

39215.patch (463 bytes) - added by sstoqnov 7 years ago.
39215.2.patch (464 bytes) - added by tyxla 7 years ago.
Improve initial patch by using wp_parse_args() instead of explode()
39215.3.patch (1.4 KB) - added by tyxla 7 years ago.
Add unit test to verify support for string $args.
39215.4.patch (1.4 KB) - added by tyxla 7 years ago.
Remove an unnecessary is_string() check

Download all attachments as: .zip

Change History (14)

@sstoqnov
7 years ago

#1 @sstoqnov
7 years ago

  • Keywords has-patch 2nd-opinion needs-testing added
  • Severity changed from normal to critical

@tyxla
7 years ago

Improve initial patch by using wp_parse_args() instead of explode()

#2 @tyxla
7 years ago

  • Keywords 2nd-opinion removed

I've updated the patch, to use wp_parse_args() instead of explode(). It's a minimal solution to support string $args, without default args. To further clarify: prior to 4.7, default values were specified in the wp_parse_args() call.

#3 @ocean90
7 years ago

  • Description modified (diff)
  • Keywords needs-unit-tests added; needs-testing removed
  • Milestone changed from Awaiting Review to 4.7.1

Does someone want to work on a unit test for this?

#4 @tyxla
7 years ago

Sure thing, I will in a bit.

@tyxla
7 years ago

Add unit test to verify support for string $args.

#5 @tyxla
7 years ago

  • Keywords has-unit-tests added; needs-unit-tests removed

39215.3.patch includes a unit test that verifies $args can also be a string.

#6 @swissspidy
7 years ago

Note that the is_string( $args ) check shouldn't be needed here.

#7 @tyxla
7 years ago

Note that the is_string( $args ) check shouldn't be needed here.

Since calling wp_parse_args() on an array $args is completely unnecessary, my point was to avoid any overhead that calling wp_parse_args() on that array would cause. But you're right that wp_parse_args() will work just fine for arrays as well, so I'm attaching an updated patch.

@tyxla
7 years ago

Remove an unnecessary is_string() check

#8 @dd32
7 years ago

  • Owner set to dd32
  • Resolution set to fixed
  • Status changed from new to closed

In 39578:

Taxonomy: Restore the ability to use string-based $args in wp_get_object_terms().

Props tyxla.
Fixes #39215

#9 @dd32
7 years ago

  • Keywords fixed-major added
  • Resolution fixed deleted
  • Status changed from closed to reopened

re-opening for 4.7.1

#10 @dd32
7 years ago

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

In 39611:

Taxonomy: Restore the ability to use string-based $args in wp_get_object_terms().

Props tyxla.
Merges [39578] to the 4.7 branch.
Fixes #39215.

Note: See TracTickets for help on using tickets.