Skip to content

stefanbohacek/fediverse-embeds-wordpress-plugin

Repository files navigation

Preview of multiple posts embedded with the Fediverse Embeds plugin.

Fediverse Embeds

Embed fediverse posts on your WordPress site. You can download it from the WordPress plugin directory, and read about the motivation behind this project on my blog.

Feedback and help will be very appreciated!

A few examples of the plugin in use:

Features

  • Show or hide post metrics

Two side-by-side screenshots comparing the same post with and without the number of likes/favorites, boosts/re-shares, and replies.

  • Automatic dark and light theme

A diagonally split screenshot of an embedded post, showing a light and dark version.

  • Labels for bots 🤖 and server admins 👑 (optional)
  • Labels for updated 📝 and deleted posts 🗑️ (see notes on how deleted posts are handled)

How to use

  1. Download and install the plugin.
  2. Add the embed code to your post.

Supported platforms

This plugin only works with fediverse platforms that provide embed code. This way, if you ever decide to stop using the plugin, your embeds will still work.

As more platforms add this feature, this plugin will continue to get updated.

Platform Supported
Mastodon ✔️ How to embed
Pleroma
Akkoma
Friendica
Misskey #17
Calckey #16
Peertube #2
Pixelfed #14

Privacy notice

When embedding a post from a fediverse server, the content of the post needs to be fetched from that server, which is then stored in your site's database. Based on the way you configure the plugin, additional requests will be made periodically to refresh the cached data.

When making requests to a third party server in general, the server will receive and may record the IP address of the server hosting your website.

Development

# install dependencies
npm install
# build front-end scripts and styles
npm run dev
# when adding new PHP classes inside `includes`
composer dumpautoload -o 

Attributions

FAQ

Images or posts are not loading

Embed code

Please make sure to copy the full embed code from the original URL of the post, including the iframe and the script tag.

API Endpoints

Please make sure that you're not blocking /wp-json/ftf/* endpoints, either via a plugin like Disable WP REST API, or through server configuration or your firewall.

Note that individual servers have an option to prevent this plugin from loading data, see more details below.

How can I run my own code after all embeds are processed?

The plugin fires a custom ftf_fediverse_embeds_posts_processed event that passes the list of processed embeds. Here's an example of how it can be used:

document.addEventListener('ftf_fediverse_embeds_posts_processed', (event) => {
    // All embeds are ready.
    event.detail.forEach(embed => {
        // Do something with each embed.
    });
});

Or with jQuery:

$(document).on('ftf_fediverse_embeds_processed', () => {
    // All embeds are ready.
    $('.fediverse-post').each(() => {
        const $post = $(this);
        // Do something with each embed.
    });
});

How can I ensure that the plugin's JS and CSS files are always loaded?

The JS and CSS files are only loaded when needed. If you for some reason need to include them on every page, you can use the FTF_FE_ALWAYS_ENQUEUE environmental variable.

define( 'FTF_FE_ALWAYS_ENQUEUE', true );

An example use case would be if you want to use some of the internal functions, eg:

if (class_exists('\FTF_Fediverse_Embeds\Embed_Posts')){
    $fediverse_embeds = new \FTF_Fediverse_Embeds\Embed_Posts();
    $embed = $fediverse_embeds->process_embeds($iframe, array(
        "blockName" => "core/html"
    ));
}

How do I prevent this plugin from embedding my posts?

The plugin will use the following user agent when making requests to your fediverse servers:

FTF: Fediverse Embeds; WordPress/VERSION; https://WEBSITE.COM

VERSION is the version of the WordPress website making the request, and WEBSITE.COM is its URL, this is the default user agent used by WordPress.

The admin of your instance can then block any requests where the user agent contains FTF: Fediverse Embeds.