Skip to content

Network connection: avoid updating the status of previously distributed posts#110

Merged
tlovett1 merged 15 commits intomasterfrom
fix/post-status
May 4, 2018
Merged

Network connection: avoid updating the status of previously distributed posts#110
tlovett1 merged 15 commits intomasterfrom
fix/post-status

Conversation

@adamsilverstein
Copy link
Copy Markdown

Description

Fixes #107.

When distributing posts, we initially set the destination post status based on the user selecting the "As Draft" checkbox:

Subsequent updates to the source post updates the destination post as well, however the post status should not be affected by these updates - the post status is controlled on the destination site. In this PR, when pushing a post to a site where that post already exists, we use its existing status (if we find it) for the update, leaving it unchanged.

Testing

  • Created a post on site A and publish.
  • Distribute post to site B as a draft (using a netowork connection)
  • Verify the destination post on site B has a status of 'draft'.
  • Change the original post and update it.
  • Check the destination post, it should still have a post status of draft. Before this PR its status is erroneously changed to publish, after this PR the status is unchanged
  • Repeat the test by distributing the post as published, then changing the origin post to a draft. Again, previous to this PR the destination post would also become a draft, after this PR the status is left unchanged.

Copy link
Copy Markdown
Contributor

@barryceelen barryceelen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update!

This change would prevent passing a post status for an existing post as it would be overwritten by the existing post status.

@barryceelen
Copy link
Copy Markdown
Contributor

barryceelen commented Apr 26, 2018

@adamsilverstein One thing to take into account is that the form on the post edit screen passes along a post status: either draft or the current post status of the original post. which obviously doesn’t matter here as that creates a new post 🤦‍♂️.

@adamsilverstein
Copy link
Copy Markdown
Author

adamsilverstein commented Apr 26, 2018

@barryceelen hmmm, i'm not sure that will work. The post status is always sent from the origin post, so your conditional checking for it will always be true for updates.

can you give it a test and add a comment describing the behavior you are expecting?

@barryceelen
Copy link
Copy Markdown
Contributor

@adamsilverstein The post status was only sent if the 'Draft' checkbox was checked. That meant however that the original post status would not be propagated if it was left unchecked.
I've updated the form and js to always send a post status.

When updating an origin post its status is not passed to the push function. The previously distributed post's status will thus not be changed.

If someone would want the origin post's status to persist across distributed posts, they could use the dt_push_post_args filter.

The behaviour I'm expecting is the same as the one you described above: by default, the post status should not be affected by updates - the post status is controlled on the destination site.

The default post status when using wp_insert_post() is draft. The push function however defaults to publish. I'm thinking for consistency we might want to change that.

@adamsilverstein
Copy link
Copy Markdown
Author

adamsilverstein commented Apr 27, 2018

@barryceelen thanks for the update and explanation of your changes. I'll give it a test and review the logic you outlined to verify its accurate.

The default post status when using wp_insert_post() is draft. The push function however defaults to publish. I'm thinking for consistency we might want to change that.

yea, we can change that - i think this was in place because if you didn't check the 'draft' box on the initial publish the status was supposed to be publish. The logic wasn't fully thought out though, and this PR aims to fix that.

Copy link
Copy Markdown
Contributor

@barryceelen barryceelen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adamsilverstein If the dt_drafts_can_be_distributed filter returns true posts with other statuses can still be distributed. The "As draft" checkbox has no effect because the check for $_POST['draft'] has not been reverted yet.

I appreciate this new restriction as an effort to make the application simpler and more understandable.
I think it is fine for folks to want to distribute posts that are scheduled, private, even pending review or draft if they are so inclined. This would now become impossible. To re-enable those statuses for syndication they could be added to the dt_drafts_can_be_distributed filter.

@tlovett1 tlovett1 merged commit 29c3d91 into master May 4, 2018
@barryceelen
Copy link
Copy Markdown
Contributor

@tlovett1 This should be reverted as the "As Draft" will not work as intended.

@tlovett1
Copy link
Copy Markdown
Contributor

tlovett1 commented May 4, 2018

Hmm, ok let me look.

@barryceelen
Copy link
Copy Markdown
Contributor

The "As draft" checkbox has no effect because the check for $_POST['draft'] has not been reverted yet.

@barryceelen
Copy link
Copy Markdown
Contributor

barryceelen commented May 4, 2018

Other than that, FWIW I think the current implementation is technically too restrictive to for other use cases. The same effect can be accomplished with a slightly different pattern while still allowing users to bypass it and pass along the new post status for their own implementation.

tlovett1 added a commit that referenced this pull request May 4, 2018
@tlovett1
Copy link
Copy Markdown
Contributor

tlovett1 commented May 4, 2018

^ That fixed it for me.

@tlovett1
Copy link
Copy Markdown
Contributor

tlovett1 commented May 4, 2018

@barryceelen can you open an issue for making this more extensible?

@helen helen deleted the fix/post-status branch August 27, 2018 20:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants