Skip to content

Instantly share code, notes, and snippets.

@ngm
Last active September 29, 2018 10:03
Show Gist options
  • Save ngm/20d98e724f7452912942cc4dc401a761 to your computer and use it in GitHub Desktop.
Save ngm/20d98e724f7452912942cc4dc401a761 to your computer and use it in GitHub Desktop.
function add_mastodon_syndication_target($synd_urls, $user_id)
{
$masto_target['uid'] = "social_coop";
$masto_target['name'] = "social.coop";
$synd_urls[] = $masto_target;
return $synd_urls;
}
add_filter("micropub_syndicate-to", "add_mastodon_syndication_target", 10, 2);
function syndicate_to_mastodon($ID, $syndicate_to)
{
$post = get_post($ID);
$message = $post->post_content;
foreach ($syndicate_to as $syndication_target_uid) {
if ($syndication_target_uid === 'social_coop') {
$instance = get_option( 'autopostToMastodon-instance' );
$access_token = get_option('autopostToMastodon-token');
$mode = get_option( 'autopostToMastodon-mode', 'public' );
$client = new Client($instance, $access_token);
$toot = $client->postStatus($message, $mode);
}
}
}
add_filter("micropub_syndication", "syndicate_to_mastodon", 10, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment