[wp-trac] [WordPress Trac] #26235: Add action when _fix_attachment_links fires

WordPress Trac noreply at wordpress.org
Mon Nov 25 14:59:59 UTC 2013


#26235: Add action when _fix_attachment_links fires
----------------------------+-----------------------------
 Reporter:  dllh            |      Owner:
     Type:  enhancement     |     Status:  new
 Priority:  normal          |  Milestone:  Awaiting Review
Component:  Administration  |    Version:  trunk
 Severity:  normal          |   Keywords:  has-patch
----------------------------+-----------------------------
 There are sometimes circumstances under which it would be useful to fire
 an action when `_fix_attachment_links()` fires, since it does a
 `wp_update_post()` right after another `wp_update_post()` has run. For
 example, say you want to run an action on `save_post` exactly once per
 post update. If a given post has attachments that need fixing, the
 `save_post` action will fire twice.

 The addition of an action within `_fix_attachment_links()` would allow
 plugins to know that the call to `wp_update_post()` was a second call and
 to remove any actions that shouldn't fire a second time.

 A real life scenario: My site hooks onto `publish_post` and initiates some
 async processes (email subscription notifications, for example). When a
 post needs its attachments updated, these processes execute twice, causing
 fun things like duplicate emails. So I need a way to make sure the events
 that fire on `publish_post` fire exactly once even if the update itself
 executes more than once. I thought adding an action might be the proper
 way forward. Patch attached.

 A sample use case:

 {{{
 function skip_async_publish_post_if_fixing_attachment_links() {
     remove_action( 'publish_post', 'queue_publish_post', 10, 2 );
 }
 add_action( '_fix_attachment_links',
 'skip_async_publish_post_if_fixing_attachment_links' );
 }}}

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


More information about the wp-trac mailing list