`wp_insert_post` doesn't save revision for new published post
|Reported by:||JamesDiGioia||Owned by:||adamsilverstein|
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:
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
which wp_save_post_revision is hooked to. Therefore, if we call wp_insert_post in a plugin to insert a post with apost_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.
Change History (14)
- Keywords needs-patch added
- Owner set to adamsilverstein
- Status changed from new to assigned