---
title: "Autoposting to FireFish from WordPress"
date: 2023-10-23T07:12:53
slug: autoposting-to-firefish-from-wordpress
tags: [code, fediverse, php, wordpress]
---
Back when I was using Mastodon, autoposting my blog posts was easy - there's no shortage of extensions for handling posting to Mastodon. But I switched to FireFish a little while ago (and for better or worse, can't easily switch back without screwing up my server's ability to federate). As far as I can find, there aren't any extensions for handling cross-posting to FireFish, so now I'm doing it manually.

It turns out at every FireFish instance also comes with it's own api docs, hosted at `https://<instance-url>/api-docs`, so that made life a bit easier. I started off by generating an API token for this task, which you can do by going to `Settings -> API -> Generate Access Token`. Make sure you save the token, because it'll only be displayed once.

Then, I added a function to a custom Wordpress plugin (or you can add it to your active theme if you know it's not going to change):

```php
function publish_to_firefish($post_id, $post, $update) {
    if (get_post_status($post_id) === "publish") {
        $excerpt = format_post_for_mastodon("", $post_id);
        wp_remote_post(
            "https://social.lewisdale.dev/api/notes/create",
            ["body" => ["text" => $excerpt, "i" => "<Your API Token>"]]
        );
    }
}
```

The `format_post_for_mastodon` function is one I was using back when I was using the syndication plugin to share to Mastodon, and it just creates the post with the excerpt:

```php
function format_post_for_mastodon( $status, $post ) {
    $status = "New post: " . $post->post_title . "\n\n";
    $status .= html_entity_decode( get_the_excerpt($post) );
    $status .= "\n\n" . get_permalink( $post );
    return $status;
}
```

Finally, hook into the `save_post` action:

```php
add_action("save_post", "publish_to_firefish", 10, 2);
```

And that should be it! With any luck, this post should have auto-shared to the fediverse. Now I just need to get my https://brid.gy clone for FireFish working so that replies, boosts, and likes are properly syndicated over.

