WordPress.org

Make WordPress Core

Opened 11 years ago

Closed 8 years ago

#16310 closed defect (bug) (fixed)

get_taxonomy_labels() and _get_custom_object_labels() fail if $object->taxonomy is not array

Reported by: foofy Owned by: wonderboymusic
Milestone: 3.7 Priority: normal
Severity: normal Version:
Component: Taxonomy Keywords: has-patch
Focuses: Cc:

Description

$object->labels is always stdObject on the taxonomy objects created by WordPress, but the get_taxonomy_labels() and _get_custom_object_labels() functions expect it to be an array and will fail otherwise.

Casting to array works fine as the functions already convert back to stdObject when they're finished.

Attachments (2)

tax-labels.patch (920 bytes) - added by foofy 11 years ago.
Casts $object->labels to array as it's what the functions expect it to be
16310.diff (1015 bytes) - added by nacin 11 years ago.

Download all attachments as: .zip

Change History (15)

@foofy
11 years ago

Casts $object->labels to array as it's what the functions expect it to be

#1 @foofy
11 years ago

  • Cc foofy@… added

#2 @scribu
11 years ago

  • Keywords has-patch added

Could you provide some steps to reproduce?

#3 @nacin
11 years ago

Sounds like you're using these functions manually, rather than letting WP call it during post type registration. Some of them are already marked private, perhaps the rest should be.

#4 follow-up: @foofy
11 years ago

This will throw a fatal "cannot use object of type stdClass as array" error at line 1174 of wp-includes/post.php:

$tax = get_taxonomy('category'); 
$labels = get_taxonomy_labels($tax);

nacin: That makes sense for _get_custom_object_labels() but get_taxonomy_labels() is a public API function.

Hope this helps.

#5 in reply to: ↑ 4 @nacin
11 years ago

Replying to foofy:

nacin: That makes sense for _get_custom_object_labels() but get_taxonomy_labels() is a public API function.

It shouldn't be. You should do this instead:

$tax = get_taxonomy('category'); 
$labels = $tax->labels;

@nacin
11 years ago

#6 @foofy
11 years ago

That makes sense. I feel that casting to array would avoid confusion later, though.

#7 @scribu
11 years ago

Should probably rename it to _get_taxonomy_labels() then?

#8 @nacin
11 years ago

Don't think that's entirely worth the effort. I'm just not sure why they were implicitly public functions to begin with.

I'm warming up to the initial patch here though.

#9 @nacin
11 years ago

  • Milestone changed from Awaiting Review to Future Release

#10 @scribu
10 years ago

Similar: #18257

#12 @wonderboymusic
8 years ago

  • Milestone changed from Future Release to 3.7

Patch still applies, this is an easy fix

#13 @wonderboymusic
8 years ago

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

In 25553:

Add @access private to _get_custom_object_labels(), which was already implied by the dangling underscore. Cast $labels to array in get_taxonomy_labels() and _get_custom_object_labels().

Props nacin, foofy.
Fixes #16310.

Note: See TracTickets for help on using tickets.