Make WordPress Core

Opened 16 years ago

Closed 13 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
Priority: normal Milestone: 3.7
Component: Taxonomy Version:
Severity: normal Keywords: has-patch
Cc: Focuses:

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 16 years ago.
Casts $object->labels to array as it's what the functions expect it to be
16310.diff (1015 bytes ) - added by nacin 16 years ago.

Download all attachments as: .zip

Change History (15)

@foofy
16 years ago

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

#1 @foofy
16 years ago

  • Cc foofy@… added

#2 @scribu
16 years ago

  • Keywords has-patch added

Could you provide some steps to reproduce?

#3 @nacin
16 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
16 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
16 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
16 years ago

#6 @foofy
16 years ago

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

#7 @scribu
16 years ago

Should probably rename it to _get_taxonomy_labels() then?

#8 @nacin
16 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
16 years ago

  • Milestone Awaiting ReviewFuture Release

#10 @scribu
15 years ago

Similar: #18257

#12 @wonderboymusic
13 years ago

  • Milestone Future Release3.7

Patch still applies, this is an easy fix

#13 @wonderboymusic
13 years ago

  • Owner set to wonderboymusic
  • Resolutionfixed
  • Status newclosed

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.