tao-software / tao-schedule-update

Wordpress Plugin to Schedule Content Updates
https://wordpress.org/plugins/tao-schedule-update/
MIT License
16 stars 14 forks source link

Doesn't copy post author #20

Open bacoords opened 6 years ago

bacoords commented 6 years ago

When I create a scheduled update, it makes my current user as the new post author, rather than the post author already assigned.

Syberspace commented 6 years ago

that's working as expected. We could, however, add a filter which would allow plugin and developers to decide which user should be set as author of a scheduled update. Is that something that would help your issue?

bacoords commented 6 years ago

There is an Author select box in the post edit screen by default- wouldn't it make more sense to copy the author already selected from the original post just like you copy any other post meta? That's what I would think anyway, but I can see both sides.

If you'd prefer, a filter would work. I could just write the function that grabs the original author from the post and assigns it if you had a filter in place.

Syberspace commented 6 years ago

Sorry for the late reply. You could use the TAO_ScheduleUpdate\before_publish_post action to copy the author from the original post to the scheduled post. https://github.com/tao-software/tao-schedule-update/blob/15b31d5751f63b996eda4a782e578296c2d10d16/tao-schedule-update.php#L689-L695

something along the lines of (this code is untested)

add_action( 'TAO_ScheduleUpdate\before_publish_post', function( $post, $orig ) {
    $post->post_author = $orig->post_author;
}, 10, 2 );
jnorell commented 6 years ago

Here's a related scenario I'm working on fixing, and sure seems buggy for out of the box behavior: I have a custom post type, and custom roles/capabilities assigned for users to be able to post that cpt; user1 creates a new cpt, then user2, who can't edit that post, can schedule a revision for it, which then replaces the original post, so user2 "steals" ownership of the post. At that point they can also edit all comments attached to the post.

In fact, one step more broken that I tried: user1 creates a cpt post; user2 schedules an update of it; user3 can then click the "Publish Now" link, which overwrites user1's post with user2's scheduled post.

I'll see what filters/actions I can hook in to to fix this, but this sure seems like a problem that should be fixed.

bacoords commented 6 years ago

@jnorell Interesting. Yes it seems odd because in WordPress, the post author only changes if you manually change it. Editing a post doesn't transfer ownership to you. That's why it feels wrong when it does that here.

@Syberspace I haven't tested it out, but should this be a filter that modifies the post object? Where we return the modified post object?

Syberspace commented 6 years ago

@bacoords the rationale behind changing the author was that you are essentially creating a new post, and for that, obviously, the currently logged in user is the author. If you just wanted to fix a typo or update an image you could just edit the post.

As for the code I posted: as mentioned, it's just an example. You will have to take care of saving the post yourself.

jnorell commented 6 years ago

To clarify, the problem I described where a user can "steal" ownership of a post via this plugin does not use the example @Syberspace posted, it's just the unmodified plugin behavior.