janboddez / share-on-mastodon Goto Github PK
View Code? Open in Web Editor NEWEasily share WordPress posts on Mastodon.
Home Page: https://jan.boddez.net/wordpress/share-on-mastodon
License: GNU General Public License v3.0
Easily share WordPress posts on Mastodon.
Home Page: https://jan.boddez.net/wordpress/share-on-mastodon
License: GNU General Public License v3.0
Using the various filters, it''s possible to POSSE entire articles. Which is nice, but posting anything over 500 characters will silently fail. I've long considered that a feature and not a bug, but it may make more sense to actually just cut off long notes.
Thanks for your work on this plugin. Is it possible to exclude specified categories from posting to Mastodon?
Rather than fetch all post types and exclude a few ones explicitly, we should just get only the public ones. Anyone wants to use any kind of special, non-public CPT after all, they can use the filter.
This plugon take the tags of the publication and add it to the publication of mastodon
I'll be happy to volunteer to your project for new Wordpress versions.
Thanks
If there's media to be uploaded, the loop will get executed 4 times, resulting in a notice/error (?) if there are less than 4 images.
Love the plugin. Small glitch with scheduled posts.
The post will not auto-share to Mastodon.
Happy to provide more details if necessary.
A block that can be added (inside of a row block, perhaps) to an entry meta area. Or a shortcode or other function that can optionally be appended to the post content.
Hi Jan,
I'm using this code in our functions file, based on your examples:
// Post Excerpt with link add_filter( 'share_on_mastodon_status', function( $status, $post ) { $status = wp_strip_all_tags( $post->post_excerpt ); $status .= "\n\n" . get_permalink( $post ); return $status; }, 10, 2 );
It's working exactly as expected. I would like to add two specific tags that will be added with every status post, with a line break after the URL. Like this:
Text
Link
Tags
I can't quite figure this out. Could you point me in the right direction?
Requesting a new token, or changing hosts, isn't very straightforward and may take more than one try. Consider a button to do this more explicitly, or even completely erase the plugin's settings.
Have the settings page verify WordPress's auth status rather than assume the presence of a token means it still has access.
I see this was opened about 2 years ago and closed as a possible option. Mastodon, like Twitter, is actually driven largely by the hashtags in the posts, so would be a very useful option to be added to the plugin. Is there any update on this, as not everyone wants to venture into editing their theme?
Apart from this, the plugin really works well, and it's a pity it is missing.
Opens log-in for instance in browser as expected but once logged in, it does not permit authorisation and instead returns the following error: "Client authentication failed due to unknown client, no client authentication included, or unsupported authentication method." Help greatly appreciated.
please consider implementing some sort of message after a post is published that indicates the status of the mastodon post
Need additional settings for items that now exist only through filters:
I have explicitly used the hook share_on_mastodon_enabled
to get posts published from the mobile app to be shared, and while it works and includes my custom content leveraging the share_on_mastodon_status
hook the featured image isn't being included.
Seems the official plugin is lagging a bit and doesn't support the share_on_mastodon_toot_args
filter that is needed for correct threading and such (should anyone else be interested in that).
Why not add compatibility with the Micropub plugin? Most users wouldn't even notice, and the few that would could disable it (this is probably technical enough that it can go behind a filter).
We currently use transition_post_status
because it runs for every post type, then return early if the post type is not supported. Going for a more specific hook (we could foreach()
over the supported post types array) may reduce this overhead.
Will require some of the (very few) tests to be rewritten.
So normally Mastodon takes an URL in the post and creates (presumably from OG tags) a little title box like at the bottom of this:
(https://zirk.us/@WISTquote/109439721919308303)
But if I post via Share On Mastodon, that doesn't automatically happen. The URL is there, but no title box. I have to Edit the post, save it, and then the little title box shows up.
You mention "Mastodon is smart enough to then try and find things like an Open Graph image and description for that URL." So I'm thinking this should work, I just don't know why it doesn't.
In my add_filter 'share_on_mastodon_status', I generate the link through this code:
$status .= "Full quote, sourcing, notes: \n" . get_permalink( $post ) . "\n\n";
Am I doing something wrong (or expecting something weird), or is this actually an issue?
Thanks for this great plugin!
Hi there,
Love the plugin, it's genuinely useful but I've noticed that alt-text on images does not get passed through to Mastodon. This results in posts getting flagged by accessibility bots.
For example this post: https://andywarburton.co.uk/2023/another-test/
Lost its alt text when transferring to Mastodon:
https://mastodon.social/@andy_warb/109627526479441029
Mastodon folks are really passionate about accessibility so I think this is an important fix. Let me know if I can help in any way.
Mastodon double-encodes already encoded entities. Default statuses should probably be stripped of all tags, then decoded, and only then submitted to Mastodon.
It's called mastodon_username
, and it might not exist (older settings).
if ( empty( $this->options['mastodon_username'] ) || $account->username !== $this->options['username'] ) {
...
}
Hi,
in most case I schedule my posts, but the plugin doesn't share it if the publish time is reached and the post online.
If I edit and update the post, it works fine.
New to Mastodon and enjoying using this to share from WordPress
I see Alt text on images is a big thing on Mastodon, is there a way to add this?
URL is not properly saved.
Workaround: save empty string, then try again.
On one of our partner's sites, the plugin auto-updated on 2022-12-20 and failed to reactivate after installation.
No PHP errors pertaining to the plugin were logged at that time.
Before the fact, the plugin was working as expected.
Let me know if I could help with more details.
https://ajdg.solutions/blog/format-your-toots-on-mastodon-when-using-share-on-mastodon/
Over the past few days I’ve been making test posts and settled on a format for toots like so: https://home.social/@arnandegans/109684410554812887.
Clean, simple, easy to read.
If you want this layout as well, add the following code to your themes functions.php file.
// Reformat the toot format/template for Share to Mastodon
function ajdg_share_on_mastodon($status, $post) {
$formatted_status = wp_strip_all_tags(html_entity_decode(get_the_title($post->ID), ENT_QUOTES | ENT_HTML5, get_bloginfo('charset'))) . "\n\n";
$formatted_status .= mb_substr(wp_strip_all_tags(html_entity_decode(get_the_excerpt($post->ID))), 0, 199, get_bloginfo('charset')) . "[…]\n";
$formatted_status .= esc_url_raw(get_permalink($post->ID)) . "\n\n";
$toot_tags = get_the_tags($post->ID);
if($toot_tags) {
foreach($toot_tags as $tag) {
$tags[] = "#" . preg_replace("/[^a-z0-9]/i", '', $tag->name);
}
$formatted_status .= implode(" ", $tags);
unset($tags, $toot_tags);
}
return $formatted_status;
}
add_filter( 'share_on_mastodon_status', 'ajdg_share_on_mastodon', 10, 2);
This basically does the same as the plugin does by default. But adds the except of the post (or a snippet if the excerpt doesn’t exist) and adds the tags. Tags with spaces do not work on Mastodon, so spaces are stripped out. And a few new lines are added for readability.
Make sure users can't select wp_template_part
and so on. All the FSE CPTs.
it looks like there currently isn't a way to include a post excerpt in the 'toots' - when i publish a post, i'm only seeing the headline on mastodon
can the filters be used for this?
The WordPress.org repo will not accept a plugin that uses cURL rather than the WP HTTP API, even if the latter means ugly code. Here's how another Mastodon crossposter does it: https://plugins.trac.wordpress.org/browser/autopost-to-mastodon/trunk/client.php#L88
As I understand it, this plugin remembers if a post has ever been shared on Mastodon, and if it has, then simply updating the post will not re-publish it on Mastodon.
However, what about old posts that were published in the past before the plugin was installed? In that case, if posts were automatically publishing on Mastodon, then simply updating one of these old (previously published on WordPress but not on Mastodon) would trigger it to be published on Mastodon.
If I'm going back and editing an old post, I wouldn't normally expect updating a change to trigger publication on Mastodon.
Would it be possible to only publish on Mastodon if it is being published on WP for the first time? I realize that might mess up when you actually intend to republish on Mastodon. Not sure how that could be worked around.
Since the notes have a generated title and I had my notes tooted I was getting redundant titles. I made this modification maybe it may be useful.
`add_filter( 'share_on_mastodon_status', function( $status, $post ) {
// Create a short preview of the post
// May be a better way to do this to check if the option is checked in the plugin.
if ( 'indieblocks_notes' === $post->post_type ) {
$status = "From my notes\n\n";
//excluding the title of the post, may want to get this from the plugin as well.
}
if ( 'post' === $post->post_type ) {
$status .= "\"" . get_the_title($post) . "\"\n\n";
}
$status .= get_the_excerpt($post);
// Remove the … forced by the excerpt and replace with the Unicode symbol
$status = html_entity_decode($status);
// Add a link
$status .= "\n\n" . get_permalink( $post );
// Add tags
$tags = get_the_tags( $post->ID );
if ( $tags ) {
$status .= "\n\n";
foreach ( $tags as $tag ) {
$status .= '#' . preg_replace( '/\s/', '', $tag->name ) . ' ';
}
}
$status = trim( $status );
return $status;
}, 10, 2 );`
I just got this installed and working, but have discovered a minor issue — I use emoji in my blog post titles, but they seem to be getting mangled and are instead just appearing in the Mastodon post as the raw HTML entity and partially turned into a Mastodon tag.
Example:
I'm not sure if this is a bug somewhere in the plugin, a bug of my own making in the PHP code I came up with for making the Mastodon post look the way I want, or if this is just something that could be resolved in a future update.
Any assistance would be appreciated! Thanks!
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.
Hi,
more a feature request question.
Would be great to be able to post on multiple mastodon site.
Seems currently the plugin can connect to just one instance.
br
It would be great if Tags in Wordpress translated to Hashtags in Mastodon.
Hello,
i have installed the Mastodon Wordpress Plugin and use with a WP Script Theme.
I want to autopost embbed video posts.
But the Plugin does not work for me. Also all other Mastodon Plugins don't work.
I can select "Videos" in the settings, but it has no effect.
I also enabled the debug, but there was no entry for this plugin.
Looked like it was not called after publishinig a new post.
br
Christian
Sometimes a post will simply not generate a share to my Mastodon account, and the only way I am aware of that is if (a) the post never shows up on Masto, and (b) the URL for the Masto link doesn't show up in the metabox. But ... there's indication of why it didn't work -- error communicating with server, or message was inexplicable too long or what. If there is a failure, could we get some sort of indication of the cause in the metabox?
Like this, sort of.
public function register_meta() {
$options = $this->options_handler->get_options();
$post_types = $options['post_types'] ?? [];
foreach ( $post_types as $post_type ) {
register_post_meta( $post_type, '_share_on_mastodon_url', [
'single' => true,
'show_in_rest' => true,
'type' => 'string',
] );
}
}
May in fact be the root cause of #17.
Jetpack's Photon module changes the image URL of thumbnails (but not, it seems, the outcome of wp_get_attachment_url()
).
This results in a broken image path, and the image is subsequently not uploaded.
This can be disabled: https://github.com/Automattic/jetpack/blob/master/projects/plugins/jetpack/class.photon.php#L707.
This may very well be the way to go. Alternatively, we could always upload the original image instead of the "large" thumbnail (when available, we fall back to the original anyways, in case it doesn't).
Note: This does normally not happen when posting from WP Admin. (It could, though, it depends.)
Would it be possible to (optionally) add a status message on the WP post edit screen when a successful share is made? This would present similarly to the existing "Post published and sending emails to subscribers. View post" or "Post updated. View post" messages, in its own status box. (WP-to-Twitter, when I was using that, did something similar.) So, something like ...
Shared to Mastodon at ____________
... filling in the location site (as the meta box does).
This would provide positive confirmation the share worked or occured, without having to scroll to where the meta box is.
The Post is shared on Mastodon only if manually edited. If a Post is created with API without the editor, the Post is not shared. You have to go manually and Update the article to be shared.
in configuration if the instance URL is given without https:// the process fails without any warning.
it would be better, if it automatically tried with https:// or warned it's required
On older WP versions and ClassicPress, at least. If and only if the image is also one of the post's attached images (which will be the case if it was uploaded through the Create Post screen).
Solution: Cast thumbnail ID to int
before comparing it to attached image ID.
The post to Mastodon for this blog post https://cogdogblog.com/2022/12/experiment-this/
published here https://social.fossdle.org/@cogdog/109508139573247437
Includes the alt text for one image (photo of a building) but skipped it for the other (screenshot of PleaseCaptionBot).
Might help prevent mobile app issues.
When a Featured Image is sent along (shouldn't this be made optional?), its alt text seems missing.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.