[wp-trac] [WordPress Trac] #30854: `wp_insert_post` doesn't save revision for new published post

WordPress Trac noreply at wordpress.org
Sun Dec 28 16:41:26 UTC 2014


#30854: `wp_insert_post` doesn't save revision for new published post
--------------------------+-----------------------------
 Reporter:  JamesDiGioia  |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Database      |    Version:  trunk
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 Calling `wp_insert_post` with `post_status` of `publish` or any other
 status on a new post doesn't save a new revision.

 The reason for this is the `$update` check at the beginning:

 https://core.trac.wordpress.org/browser/tags/4.1/src/wp-
 includes/post.php#L3085

 checks whether or not the args include an ID, indicating that we're
 updating a post. Further down, that update check is what calls
 `post_updated`

 https://core.trac.wordpress.org/browser/tags/4.1/src/wp-
 includes/post.php#L3473

 which `wp_save_post_revision` is hooked to. Therefore, if we call
 `wp_insert_post` in a plugin to insert a post with a`post_status` of
 `publish`, WordPress doesn't save a post revision.

 Post revisions are supposed to be up-to-date with the latest post data,
 but we don't get a revision if we insert a post in this manner. I think
 the reason we ended up with this is to avoid saving a revision of the
 auto-draft that is created when opening up post-new.php, but that isn't
 necessary now, as `wp_save_post_revision` checks whether the `post_status`
 is an auto-draft.

 I think the easiest solution is to move the `wp_save_post_revision` to the
 `save_post` hook, but I'm not sure if there are other places in the
 codebase this would cause issues.

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


More information about the wp-trac mailing list