Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save autoshare meta from post form before publishing tweet #82

Merged
merged 4 commits into from
Feb 24, 2020

Conversation

johnwatkins0
Copy link
Member

@johnwatkins0 johnwatkins0 commented Feb 18, 2020

Description of the Change

This resolves a bug brought up by @rickalee in #80. Autoshare form data is saved in save_post while the tweet action runs on transition_post_status. transition_post_status runs earlier than save_post, so the bug happened in the case where:

  1. The post is switching from from a non-publish status to publish
  2. AND the autoshare status is switching from enabled to disabled.

In this case, the enabled status has not been saved before the tweet function runs, so the post is tweeted.

This update causes the form data to be processed before trying to tweet.

Alternate Designs

I'm wanting to refactor large parts of this plugin, but I'm holding for now and will aim to submit issues outlining the specific technical debt I'm seeing.

Benefits

Tweets won't be inadvertently published during the specific scenario outlined above.

Possible Drawbacks

Verification Process

  1. Create a new post
  2. Leave 'Tweet this Post' checked
  3. Save Draft
  4. Uncheck 'Tweet this Post'
  5. Save Draft/Publish
  6. Post should not be tweeted

Checklist:

  • I have read the CONTRIBUTING document.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my change.
  • All new and existing tests passed.

Applicable Issues

Resolves #80

Changelog Entry

Fix a bug that caused posts to be inadvertently tweeted when switching from draft to publish

@johnwatkins0 johnwatkins0 self-assigned this Feb 18, 2020
@johnwatkins0 johnwatkins0 added this to the 1.1.0 milestone Feb 18, 2020
@rickalee
Copy link
Contributor

Confirmed all looks good on our side. Packaging up for client bugfix and will follow up if they catch anything.

@rickalee
Copy link
Contributor

No reported issues after pushing to client site as hotfix and confirmed Twitter timeline looks good. Thanks @johnwatkins0 . I think we can safely add to next release.

@jeffpaul
Copy link
Member

@johnwatkins0 are there any tests that we can add to cover this to avoid a regression back to this behavior later?

@johnwatkins0
Copy link
Member Author

@jeffpaul Yes, we could definitely increase test coverage. I'll look into adding a unit test for this particular PR later. I'd also like to try #19 to see how well WPAcceptance can cover this sort of thing, but that should probably be a separate task because it will involve setting up acceptance tests and probably adding more than just this one.

@jeffpaul
Copy link
Member

@rickalee @johnwatkins0 did either of you want/need to ship a v1.0.2 for this or hold and include in a larger v1.1.0 later?

return;
}

$form_data = sanitize_autoshare_for_twitter_meta_data(
// Using FILTER_DEFAULT here as data is being passed to sanitize function.
filter_input( INPUT_POST, META_PREFIX, FILTER_DEFAULT, FILTER_REQUIRE_ARRAY )
Copy link
Member Author

Choose a reason for hiding this comment

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

Broke this out into a function (see below) for easier testing.

@johnwatkins0
Copy link
Member Author

I added some tests and also did some cleanup around meta saving. Sorry about the growing diff, @dinhtungdu .

I'm aiming to use my extra time over the next few days to set up WP Acceptance ahead of a 1.1.0 release, but I'll work on that in a separate PR.

Copy link
Contributor

@dinhtungdu dinhtungdu left a comment

Choose a reason for hiding this comment

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

Worked great in my tests! 🎉

@jeffpaul jeffpaul merged commit 7e8dfa4 into develop Feb 24, 2020
@jeffpaul jeffpaul modified the milestones: 1.1.0, 1.0.2 Mar 8, 2020
@jeffpaul jeffpaul deleted the fix/unwanted-tweets-in-status-transition branch June 30, 2020 19:16
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.

Tweet shared when unchecked
4 participants