janboddez / share-on-mastodon

Easily share WordPress posts on Mastodon.
https://jan.boddez.net/wordpress/share-on-mastodon
GNU General Public License v3.0
39 stars 5 forks source link

RFE: Content warnings #36

Closed swaldman3 closed 1 year ago

swaldman3 commented 1 year ago

On some Mastodon instances it is considered polite to add a content warning for bot-posted toots like these. I would love to be able to have a configurable content warning, ideally one which allowed the CW to include the title of the Wordpress post.

Thanks for considering.

janboddez commented 1 year ago

Alright, I think a sort of semi-automated CW (“new blog post” or something, maybe based on tags or similar) is already possible through the current filter mechanism (but would require some custom PHP).

Let me get back to you with a code example once I’ve figured this out.

The alternative would be an extra text field for a completely “manual” CW. I was hoping to eventually rework the meta box anyway, but I might be able to something even before that happens.

janboddez commented 1 year ago

OK, so it is possible to add the following to, e.g., a functions.php file or similar.

add_filter( 'share_on_mastodon_toot_args', function( $args ) {
  $args['spoiler_text'] = 'new blog post';

  return $args;
} );

Unfortunately, it doesn't look like global $post can be used to retrieve the post title as well.

I can add an optional second argument ($post) to that filter in a next version.

janboddez commented 1 year ago

OK, so with that new parameter (not up on WP.org, yet!) you should be able to do something like:

add_filter( 'share_on_mastodon_toot_args', function( $args, $post = null ) {
  $args['spoiler_text'] = 'new blog post';

  if ( $post ) {
    $args['spoiler_text'] .= ': ' . get_the_title( $post );
  }

  return $args;
}, 10, 2 );

And then you could either modify $args['status'] or use the share_on_mastodon_status filter to modify the actual text, like change it into an excerpt + a permalink, or include tags, etc. Or you could fetch the post's tags right there and base your CW off them, and so on, and so on.

Not sure when I'll push to WP.org, maybe in a week or so. Could be in the future I add a CW setting, but it will probably be limited to static text (which you could then override using the filter).

swaldman3 commented 1 year ago

thanks!

gloriousnoise commented 1 year ago

Thank you!