Skip to content

Instantly share code, notes, and snippets.

@janboddez
Created January 13, 2024 15:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janboddez/c9027bacbfaaedb8c2a837a5589eba11 to your computer and use it in GitHub Desktop.
Save janboddez/c9027bacbfaaedb8c2a837a5589eba11 to your computer and use it in GitHub Desktop.
<?php
// Always share asides, even if their checkbox is disabled. So if you had the
// plugin's "opt in" option enabled, this would share all asides, plus whatever
// posts (regardless of their format) have sharing enabled explicitly.
add_filter( 'share_on_mastodon_enabled', function ( $is_enabled, $post_id ) {
if ( 'aside' === get_post_format( $post_id ) ) {
return true;
}
return $is_enabled;
}, 10, 2 );
@janboddez
Copy link
Author

janboddez commented Jan 13, 2024

Note that you can't actually disable crossposting this way: if the checkbox is checked and the post saved, it will get crossposted. (The plugin used to allow that sort of thing, but I had to rewrite bits of it for all sorts of reasons, and, well, it is what it is.)

So you can override an unticked checkbox, but not a checked one.

Most folks are anyway interested in forcing crossposting even if the checkbox value doesn't get saved, because it can't, like when they post from a mobile app. Which is why I came up with a "Share Always" setting.

Which is why I wanted to deprecate the share_on_mastodon_enabled filter (as "wrongly" mentioned in the docs), even though I haven't, and likely never will. I should correct the documentation. In fact, I should probably rename the filter to share_on_mastodon_share_always, because it basically overrides that setting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment