[wp-trac] [WordPress Trac] #17817: do_action/apply_filters/etc. recursion on same filter kills underlying call

WordPress Trac noreply at wordpress.org
Fri Dec 21 13:28:41 UTC 2012


#17817: do_action/apply_filters/etc. recursion on same filter kills underlying call
-----------------------------------+------------------------------
 Reporter:  kernfel                |       Owner:
     Type:  defect (bug)           |      Status:  reopened
 Priority:  normal                 |   Milestone:  Awaiting Review
Component:  Plugins                |     Version:  3.4.1
 Severity:  normal                 |  Resolution:
 Keywords:  2nd-opinion has-patch  |
-----------------------------------+------------------------------
Changes (by cheeserolls):

 * cc: dh@… (added)
 * keywords:  2nd-opinion => 2nd-opinion has-patch
 * severity:  minor => normal


Comment:

 foo123's solution works, but it's slow because when we execute
 $foo=wp_filter[$tag]    the whole (often very large) array gets copied to
 a new variable $foo.

 Instead, I suggest this version:


 {{{
 foreach ($wp_filter[$tag] as &$action_to_execute) {
         foreach ((array)$action_to_execute as $the_)
                 if ( !is_null($the_['function']) )
                         call_user_func_array($the_['function'],
 array_slice($args, 0, (int) $the_['accepted_args']));
 }
 }}}


 As with foo123's solution, a new dummy variable is used -
 $action_to_execute - but it's created by reference, so the array isn't
 copied.  All nested actions get executed.  Furthermore, I did some
 benchmarking tests, and found that this is actually quicker than the
 current implementation. (see above attached file).

 I think this really should be fixed ASAP.

 It's a serious bug, because a plugin author cannot safely call wordpress
 functions like wp_update_post() from inside an action.  (Unless he/she
 first reads the entire source code for wp_update_post() and all other
 functions that are used, to make sure that the same action isn't called).

 Also, it specifically affects blogs with both WPML and ACF plugins
 installed (2 of the most common plugins in WP).  ACF and WPML both use the
 'save_posts' action, and this bug prevents ACF's 'save_post' action being
 called.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/17817#comment:12>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list