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

WordPress Trac wp-trac at lists.automattic.com
Fri Jul 13 14:23:25 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:
 Severity:  minor         |  Resolution:
 Keywords:                |
--------------------------+------------------------------

Comment (by mrubiolvn):

 {{{
 function dummyfunc($postId) {
         $post = get_post($postId);
         $childPosts = get_posts( 'post_parent='.$postId );
         foreach($childPosts as $childPost) {
                 $childPost->post_title = 'whatever';
                 wp_update_post($childPost);
         }
         error_log(__FUNCTION__.' triggered for post id:'.$postId);
 }
 function dummyfunc2($postId) {
         error_log(__FUNCTION__.' triggered for post id:'.$postId);
 }

 add_action('save_post','dummyfunc',10);
 add_action('save_post','dummyfunc2',15);
 }}}

 Now the flow would be like this:

 save_post is triggered, and eventually dummyfunc is executed.
 It saves a child post, so save_post is triggered again, only for the child
 post this time.
 At this point, $wp_filter [ 'save_post' ] pointer is reset. When we're
 done with all the filters for the child post, and any other child posts,
 the execution will continue right after where we left it with the initial
 post. Now, we do execute next(or each with #21169) over $wp_filter [
 'save_post' ]. But the pointer will likely be on the end of the array, so
 dummyfunc2 will not be executed for the initial post.

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


More information about the wp-trac mailing list