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

Add filter to allow autoshare to be enabled by default for a post type #71

Merged
merged 7 commits into from
Jan 30, 2020

Conversation

johnwatkins0
Copy link
Member

@johnwatkins0 johnwatkins0 commented Jan 29, 2020

Description of the Change

This adds a filter, autoshare_for_twitter_enabled_default, that receives the post type of the current post and allows the default enabled value for the post type to be overridden. Without the filter applied, the default is false.

Alternate Designs

#57 should introduce a corresponding UI component for this -- e.g., a series of checkboxes for public post types.

Benefits

Less work for editors when they know a post type will always be shared.

Possible Drawbacks

Using the update requires a small amount of engineering effort to apply the filter.

Verification Process

Add this filter to a theme or plugin on the same site:

function enable_autoshare_by_default_for_core_post_type( $enabled, $post_type ) {
	if ( 'post' === $post_type ) {
		return true;
	}

	return $enabled;
}
add_filter( 'autoshare_for_twitter_enabled_default', 'enable_autoshare_by_default_for_core_post_type', 10, 2 );

(This example is also included in this PR in README.md.)

When this filter is active, autoshare should be enabled by default for the core post post type but not on any other post types. When the filter is removed, autoshare should again be disabled by default.

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 #68

Changelog Entry

Add filter to allow autoshare to be enabled by default for a post type.

@johnwatkins0 johnwatkins0 self-assigned this Jan 29, 2020
@jeffpaul jeffpaul added the type:enhancement New feature or request. label Jan 29, 2020
@jeffpaul jeffpaul requested a review from dinhtungdu January 29, 2020 15:09
@jeffpaul jeffpaul added this to the 1.1.0 milestone Jan 29, 2020
README.md Outdated Show resolved Hide resolved
@rickalee
Copy link
Contributor

rickalee commented Jan 29, 2020

@johnwatkins0 Should we be showing checkbox as checked in Classic Editor once filter is in place as well as allow user to toggle off?

https://rickal.ee/p9u5mk90

@johnwatkins0
Copy link
Member Author

Good call, @rickalee . Added this commit to pass the enabled status to the classic editor checkbox: 60af3b7

@rickalee
Copy link
Contributor

@johnwatkins0 Checkbox is now checked but on Publish it doesn't tweet.

https://rickal.ee/DOuv7mep

@johnwatkins0
Copy link
Member Author

Thanks, @rickalee This last commit should do it: 13bbad4 Did an extra round off testing myself this time 😅

@@ -68,7 +100,7 @@ function delete_autoshare_for_twitter_meta( $id, $key ) {
* @return bool
*/
function maybe_autoshare( $post_id ) {
return ( 1 === intval( get_autoshare_for_twitter_meta( $post_id, ENABLE_AUTOSHARE_FOR_TWITTER_KEY ) ) ) ? true : false;
return ( 1 === intval( autoshare_enabled( $post_id ) ) ) ? true : false;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we remove this function? maybe_autoshare() is only used in post-transition.php:88. And it's just a wrapper for autoshare_enabled.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, good idea. I have updated in bf7f444

@dinhtungdu dinhtungdu self-requested a review January 30, 2020 00:12
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.

Great work, John!

@johnwatkins0 johnwatkins0 merged commit 0ea3fb9 into develop Jan 30, 2020
@johnwatkins0 johnwatkins0 deleted the feature/enable-for-post-type-by-default branch January 30, 2020 02:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:enhancement New feature or request.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add filter to turn on autoshare by default on a per-post-type basis
4 participants