• Resolved swemaniac

    (@swemaniac)


    Hi guys I thought I’d post here before reporting this as an issue.

    I use wp_insert_post in a script that runs via cron and therefore not as a logged in user. I manually set post_author to an existing user. When I insert a new post this works as expected (the author is set), but when I use this method to update an existing post a revision is created with the author set to 0 (blank).

    I traced this down to the _wp_post_revision_fields function in revision.php which strips the post_author field from the post object before the revision is saved via wp_insert_post which in turn tries to get the currently logged in user.. Which is non-existant..

    Right now the non-obtrusive solution would be to use the _wp_put_post_revision action to update the revision with the correct author.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter swemaniac

    (@swemaniac)

    My temporary solution uses the wp_insert_post_data filter to intercept when a revision is being saved for my particular post type, and if the author is set to 0, I update it.

    I still wonder if I should report this as an issue?

    Moderator bcworkz

    (@bcworkz)

    It’s pretty clear to me this is intentional behavior, though I’ve no idea about the underlying reasoning. It’s obviously an issue for your particular situation. Hard to say if your issue is more important than the initial reason for stripping values. It may turn out removing the author from the list of fields to strip would not impact anything else.

    The only way to find out is to ask. Even if nothing is changed, you may gain insight into why it’s the way it is. I would approach it as more of a feature request than a bug report, but that may result in not getting the attention you desire. You’ll need to decide for yourself if or how to approach this.

    Honestly, if it were me, since a simple filter hook fixes it, I wouldn’t bother reporting it since it appears to be intentional behavior.

    Thread Starter swemaniac

    (@swemaniac)

    Thanks for the insight, I probably won’t report it since it was an easy “fix” in this case.

    Thread Starter swemaniac

    (@swemaniac)

    resolved..

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Update post outside WP causes revision with no author’ is closed to new replies.