[wp-trac] [WordPress Trac] #23148: Add hook in wp_ajax_save_attachment for additional attachment fields

WordPress Trac noreply at wordpress.org
Mon Mar 6 03:03:23 UTC 2023


#23148: Add hook in wp_ajax_save_attachment for additional attachment fields
-------------------------------------------------+-------------------------
 Reporter:  griffinjt                            |       Owner:  audrasjb
     Type:  enhancement                          |      Status:  closed
 Priority:  normal                               |   Milestone:  6.2
Component:  Media                                |     Version:  3.5
 Severity:  normal                               |  Resolution:  fixed
 Keywords:  has-patch 2nd-opinion dev-feedback   |     Focuses:
  needs-dev-note needs-docs                      |
-------------------------------------------------+-------------------------

Comment (by peterwilsoncc):

 I could be convinced either way but I kind of agree with Aaron here, that
 it doubles up a lot of actions from the `wp_insert_post()` function.
 Documenting the use of `doing_action( 'wp_ajax_save-attachment' )` adds to
 the confusion, as that seems something that can be done in the existing
 hooks.

 It would be good to know what the advantage is that this brings that could
 not be achieved by:

 {{{#!php
 <?php
 add_action( 'wp_after_insert_post', function( $post, $is_update,
 $post_before ) {
  if ( ! doing_action( 'wp_ajax_save-attachment' ) ) {
   return;
  }

  // Etc, etc.
 }, 10000, 3 );
 }}}

 `wp_after_insert_post` chosen because it's the hook that runs immediately
 prior to this one but this could apply to many of the hooks mentioned
 earlier.

 It's also worth noting that a
 [https://wpdirectory.net/search/01GTTDMTZAFGPDRZRZYPMXAW2F few plugins
 replace] the  `wp_ajax_save-attachment` and die prior to the core version
 running (the highest I saw has 200K installs) so advising people move to
 the new hook may cause problems until such plugins implement it. I've done
 it once or twice in my client services days when implementing DAMs.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/23148#comment:54>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list