[wp-trac] [WordPress Trac] #8723: Instances of same class that call variable hook first generate same wp_filter_id

WordPress Trac wp-trac at lists.automattic.com
Fri Dec 26 04:34:22 GMT 2008


#8723: Instances of same class that call variable hook first generate same
wp_filter_id
--------------------------+-------------------------------------------------
 Reporter:  bkrausz       |       Owner:     
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  2.8
Component:  Plugins       |     Version:  2.7
 Severity:  normal        |    Keywords:     
--------------------------+-------------------------------------------------
 Best shown by example:
 {{{
 <?php
 class Foo {
   var $i;
   function Foo($i) {
     $this->i = $i;
     add_action('something'.$i, array(&$this, 'bar'));
     add_action('init', array(&$this, 'baz'));
   }
   function bar() {}
   function baz() {
     echo $this->i;
   }
 }

 new Foo(1);
 new Foo(2);
 ?>
 }}}

 This results in only seeing "2".  This is because
 _wp_filter_build_unique_id sets $function[0]->wp_filter_id to 0 for both.
 The following line is the issue:

 {{{
 $count = isset($wp_filter[$tag][$priority]) ?
 count((array)$wp_filter[$tag][$priority]) : 0;
 }}}

 Since add_action is being called for the instance for a unique $tag in its
 first instance, $wp_filter[$tag][$priority] is empty for both
 instances...there should be some way to prevent this.

 This may seem like a rare case, but I had to hunt this down for my plugin
 when the first action was:
 {{{
 add_action('wp_ajax_add-' . $this->slug, array(&$this, 'ajax_add'));
 }}}

 The fix is trivial: call add_action on something with a static name first,
 but is difficult to discover.

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


More information about the wp-trac mailing list