Make WordPress Core

Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#14914 closed defect (bug) (invalid)

Potential Bug in wp_update_term() when using get_term filter

Reported by: jfarthing84's profile jfarthing84 Owned by:
Milestone: Priority: normal
Severity: major Version: 3.0.1
Component: Taxonomy Keywords: dev-feedback
Focuses: Cc:

Description

Here's the situation: I am using the "get_term" filter to automatically load other related term objects.

For instance, I have a "widget" taxonomy that is related to the "factory" taxonomy. I store the "factory" ID in the "widget" term taxonomy meta table I have created. Then, using the "get_term" filter, I automatically load the "factory" term object as a property of the "widget" term object.

The problem arises when wp_update_term() is called with an object as a property of the term because of the call to add_magic_quotes() call on the term immediately. It expects strings only.

This seems like it defeats the purpose of the "get_term" filter if I can't add to the object without crashing WP.

So, in order to prevent this from happening, there should be some kind of filtering mechanism when wp_update_term() is called, as to only pass the default term properties into the validation functions. Perhaps even a "pre_update_term" filter would work, called before get_term() so that the "get_term" filter could be removed before hand.

Change History (5)

#1 @mdawaffe
13 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

Interesting issue.

http://core.trac.wordpress.org/browser/tags/3.0.1/wp-includes/taxonomy.php#L481 says that that functions hooked to the get_term filter must return a taxonomy object, which your function is not doing.

I suggest refactoring your code. Maybe with a my_get_widget_factory( $widget_term_id ) function or equivalent.

#2 follow-up: @jfarthing84
13 years ago

  • Resolution invalid deleted
  • Status changed from closed to reopened

Actually, I am returning a taxonomy object, along with additional properties.

#3 in reply to: ↑ 2 @mdawaffe
13 years ago

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

Replying to jfarthing84:

Actually, I am returning a taxonomy object, along with additional properties.

A taxonomy object looks like:

stdClass::__set_state(array(
   'term_id' => '1',
   'name' => 'Uncategorized',
   'slug' => 'uncategorized',
   'term_group' => '0',
   'term_taxonomy_id' => '1',
   'taxonomy' => 'category',
   'description' => '',
   'parent' => '0',
   'count' => '36',
))

From what I gather, you're returning something like:

stdClass::__set_state(array(
   'term_id' => '1',
   'name' => 'Uncategorized',
   'slug' => 'uncategorized',
   'term_group' => '0',
   'term_taxonomy_id' => '1',
   'taxonomy' => 'category',
   'description' => '',
   'parent' => '0',
   'count' => '36',
   'something' => 
  stdClass::__set_state(array(
     'term_id' => '165',
     'name' => 'tag',
     'slug' => 'tag',
     'term_group' => '0',
     'term_taxonomy_id' => '167',
     'taxonomy' => 'post_tag',
     'description' => '',
     'parent' => '0',
     'count' => '0',
  )),
))

That "additional property" is unsupported and is not a "taxonomy object" as far as WordPress is concerned, so this is not a bug.

It may not fit your aesthetic, but I believe there is a perfectly functional workaround for what you're trying to do.

#4 @jfarthing84
13 years ago

That brings me back to the fact that it defeats the purpose of having a filter if I can't modify the object.

#5 @nacin
13 years ago

You can modify the object -- you just can't decorate it with invalid properties.

Note: See TracTickets for help on using tickets.