Make WordPress Core

Opened 2 years ago

Last modified 2 years ago

#52635 assigned defect (bug)

Save revisions on the `wp_after_insert_post` action

Reported by: peterwilsoncc's profile peterwilsoncc Owned by: adamsilverstein's profile adamsilverstein
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Revisions Keywords: needs-patch needs-testing needs-dev-note
Focuses: rest-api Cc:

Description

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 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 14 plugins (the highest with 3,000,000+ installs) and 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.

Change History (1)

#1 @adamsilverstein
2 years ago

  • Owner set to adamsilverstein
  • Status changed from new to assigned

Great suggestion @peterwilsoncc I was thinking the same when the new hook was added. I'll try to look into this further. Thanks for the plugin reference, that is helpful to have to ensure we don't break backwards compatibility.

Note: See TracTickets for help on using tickets.