[wp-trac] [WordPress Trac] #26339: Pass by reference in wp_get_object_terms()

WordPress Trac noreply at wordpress.org
Sat Nov 30 11:58:06 UTC 2013


#26339: Pass by reference in wp_get_object_terms()
---------------------------+-----------------------------
 Reporter:  stephenharris  |      Owner:
     Type:  defect (bug)   |     Status:  new
 Priority:  normal         |  Milestone:  Awaiting Review
Component:  Taxonomy       |    Version:  trunk
 Severity:  normal         |   Keywords:
---------------------------+-----------------------------
 Hi, I've noticed a bug in the current beta version:
 '''3.8-beta-1-26375'''. I've tracked it down to this patch:
 http://core.trac.wordpress.org/attachment/ticket/17646/17646.3.diff
 (#17646).

 Each term in the `foreach` of the `$terms` array is passed by reference
 when sanitising the term. However, this is not unset after the `foreach`
 loop.

 As such the seemly innocuous code changes the last term from an object to
 an integer:


 {{{
 add_filter( 'wp_get_object_terms', 'my_get_object_terms_callback' );
 function my_get_object_terms_callback( $terms ){

         // var_dump reveals an array of objects

         $term_ids = wp_list_pluck( $terms, 'term_id' );

         // last term is now an integer

         return $terms;
 }
 }}}


 ( I'm aware `wp_get_object_terms` filter isn't necessarily filtering term
 ''objects'', but this highlights the bug).

--
Ticket URL: <http://core.trac.wordpress.org/ticket/26339>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list