I am writing a plugin which will enable to write posts from front-end. Those posts have to be checked by admin before published. Now if admin edits the post or publishes the post, the post author is changed from the original author to admin. How can I prevent that?
Leave a Reply
You must be logged in to post a comment.
The administrative editors could fix the author manually.
Alternatively, you could add custom post meta-data to designate the original author. Then, hooking into the
publish_post
ortransition_post_status
actions (or evensave_post
for that matter) you could check for the presence of the meta-data when a post is being published, and if it exists, replace the post’s author with the original from the meta-data.Attempting to knock it out with one hook:
A check for
!is_admin()
in there somewhere could also be useful to confirm that the user is somewhere on the front-end of the site.I experienced the same problem a couple of weeks ago. My problem was that I was using a custom post type and I didn’t add support for author.
It was always published by the correct author but when admin changed post status or updated the post the admin becomes the post author.
Try adding support for author and see if that helps!
That seems like a very strange issue. The status of a post should not affect the user setting.
Have you considered using Gravity Forms? It is a paid plugin but it does a nice job with creating the forms and it is relatively simple to create a front end form that creates a post automatically (in either
published
ordraft
orreview
state).