I was trying to syndicate from my website so that the post on Mastodon would credit my website for the post and link back to my homepage as the application that made the post. You’ll notice at the bottom of the post there’s the post date and a globe icon, which indicates the post is public, followed by my website name ‘BoffoSocko.com’ and details about replies, reposts, and favorites.
I assuredly won’t release a public plugin for WordPress that does this. But since some have asked how I did it, I thought I’d share some of the internals of a few WordPress plugins that one can quickly modify to achieve the same thing.
That I can currently see, there are three plugins in the repository that will allow one to syndicate content to a variety of Mastodon instances. They are Mastodon Autopost, Mastodon Auto Share, and Share on Mastodon. The first two are closely related and essentially replicate the same codebase.
Similar to using Twitter’s API to crosspost, Mastodon is looking for two bits of information when an application is registered: a client name and a website URL.
Mastodon Autopost and Mastodon Auto Share, both have a file called client.php
which define these two variables.
public function register_app($redirect_uri) { $response = $this->_post('/api/v1/apps', array( 'client_name' => 'Mastodon Share for WordPress', 'redirect_uris' => $redirect_uri, 'scopes' => 'write:statuses write:media read:accounts', 'website' => $this->instance_url ));
You can edit this file with a text editor to change the 'client_name'
from 'Mastodon Share for WordPress'
to 'Anything You Want'
. If you’re in a joking mood, maybe change it to 'Twitter'
?
To change the URL so that the link on the client_name
directs to your website, you’ll want to change the line 'website' => $this->instance_url
.
In particular change $this->instance_url
to 'https://example.com'
where example.com would be your website. I’ll note that $this->instance_url
on this line in the original plugin is a bug. If left alone, it points the URL to your home Mastodon instance instead of to the more logical https://wordpress.org/plugins/autopost-to-mastodon/
where the plugin lives.
If you prefer using Jan Boddez‘ excellent plugin, you’ll want to do something similar, except in that case you’ll want to change a file named class-options-handler.php
in the includes
folder.
Here you’ll want something like:
'client_name' => __( 'Example.com' ),
But note that Boddez doesn’t have a similar bug, so the website line
'website' => home_url(),
is already correctly defined so that your website will automatically be linked without any changes to it.
If you’re already using one of these plugins and manually modify them, note that you’ll probably need to re-authorize the plugin so that the changes propagate.
This post was originally published on Chris Aldrich