• I want to know that if a post is updated via REST API, is revision history for it created?

    • This topic was modified 4 years, 2 months ago by fid.
Viewing 7 replies - 1 through 7 (of 7 total)
  • Moderator bcworkz

    (@bcworkz)

    Try an update and find out 🙂
    A revision history is kept when I do so on my site. I can’t guarantee you’ll have the same experience, although you should. Testing is the only way to know for sure.

    Thread Starter fid

    (@fid)

    It doesn’t update revision history when updating posts via REST API.

    Is there a way to make this work?

    Moderator bcworkz

    (@bcworkz)

    It could be an add-on module inhibiting revision creation. Deactivate all plugins and switch to a default twenty* theme. Update a post via the API using cookie authentication. A revision post should be created. Restore your theme and plugins, one at time. Test updates after each. When revisions fail to appear, the last activated module is inhibiting revisions.

    Thread Starter fid

    (@fid)

    Thanks, but I do not have any other plugins and I am using the default theme. I should probably say this, but all I am doing is updating custom fields of a post via the REST API. It still does not create a revision. However, if I change the custom field value via the dashboard and save it from there, it does create the revision. But REST API updates are not creating revisions.

    Any other suggestions?

    Moderator bcworkz

    (@bcworkz)

    I see. Post meta updates via the API do not affect the posts table, so it’s not seen as an “update” for which a revision should be created. When you update from the dashboard, the entire post data set is sent to the server so it’s seen as an update even when no post table data had changed.

    I suppose you could insert your own revision post via API when updating only post meta.

    Thread Starter fid

    (@fid)

    @bcworkz OK, I’m not sure what you mean. Are you saying that I update something in the posts table via the API which will trigger the revision? If that’s the case, I can’t really do that due to the way my setup is done. I only update post meta via the API.

    Is there some hook I can use that will trigger post revision when post meta is updated?

    • This reply was modified 4 years, 2 months ago by fid.
    • This reply was modified 4 years, 2 months ago by fid.
    Moderator bcworkz

    (@bcworkz)

    When post data that resides in the post table is updated via the API, a revision is created. Not so when only post meta is updated.

    The API still calls update_post_meta(), so you could hook “update_postmeta”, verify REST_REQUEST is true, then insert your own revision post record. The problem then is there could be two revisions if post table data is also updated. You’d need to check for yourself if the current post has changed from the last revision. If it has, don’t insert a revision post since WP will do that itself.

    There might be an easier way. I’ve not tested it to verify. Hook something early like “rest_init” and verify the request is updating post meta. If so, hook “wp_save_post_revision_post_has_changed” and return true. This should cause a revision to be created even if the post table data has not changed.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘WP REST API – Revision History’ is closed to new replies.