[wp-trac] [WordPress Trac] #52635: Save revisions on the `wp_after_insert_post` action

WordPress Trac noreply at wordpress.org
Wed Feb 24 02:54:09 UTC 2021


#52635: Save revisions on the `wp_after_insert_post` action
-------------------------+-------------------------------------------------
 Reporter:               |      Owner:  (none)
  peterwilsoncc          |
     Type:  defect       |     Status:  new
  (bug)                  |
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  Revisions    |    Version:
 Severity:  normal       |   Keywords:  needs-patch needs-testing needs-
  Focuses:  rest-api     |  dev-note
-------------------------+-------------------------------------------------
 Currently revisions are created on the `post_updated` hook which fires
 within `wp_insert_post()`, `wp_publish_post()` and related functions.

 The call to `wp_save_post_revision()` is added by core as a default
 action:

 {{{
 add_action( 'post_updated', 'wp_save_post_revision', 10, 1 );
 }}}

 For sites wishing to [https://wordpress.org/plugins/wp-post-meta-
 revisions/ save meta data with their revisions via a plugin] this occurs
 prior to meta data saving been saved in the rest api and therefore the
 block editor. This results in an off-by-one error for the meta data stored
 against each revision.

 Moving the generation of revisions to the `wp_after_insert_post` hook
 added in WordPress 5.6 will ensure that the post object, terms and meta
 data have all been saved before the revision is generated.

 As the `wp_after_insert_post` hook fires on both post creation and post
 update, a ''maybe save'' wrapper function may be needed to determine if
 the revisions should actually be generated. (Or a `wp_after_update_post`
 hook but ideally not.)

 Related #20564, #45114.

 **Backward compatibility**

 A search of the WordPress repositories show that
 [https://wpdirectory.net/search/01EZ8YW9Y3KZPZ9A1WRBKJA6KC 14 plugins]
 (the highest with 3,000,000+ installs) and
 [https://wpdirectory.net/search/01EZ8YXYTZEF19GWH3FE0Y1Y2A zero themes]
 are de-registering the default action to save revisions.

 To maintain backward compatibility WP might need to allow for removing the
 hook on `post_updated`.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/52635>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list