Skip to content

Instantly share code, notes, and snippets.

View janboddez's full-sized avatar

Jan Boddez janboddez

View GitHub Profile
<?php
add_action( 'activitypub_safe_remote_post_response', function( $response, $url, $body, $user_id ) {
$activity = json_decode( $body );
if ( empty( $activity->type ) || 'Create' !== $activity->type ) {
error_log( 'Not a Create activity.' );
return;
}
<?php
/**
* Adds video to Share on Mastodon's attachment array by hooking into Share on
* Mastodon's `share_on_mastodon_media` filter.
*
* Just drop this file into `wp-content/mu-plugins`.
*
* @param array $media Array of up to 4 image IDs.
* @param WP_Post $post Post object.
<?php
// Exclude "likes" and "reposts" from comment count. We'd use a comment query but there's a weird bug that messes up counts when using meta query.
add_filter( 'get_comments_number', function( $count, $post_id ) {
if ( is_admin() ) {
return $count;
}
if ( ! is_singular() ) {
return $count;
<?php
add_filter( 'share_on_mastodon_status', function( $status, $post ) {
// Apply `the_content` filters so as to have smart quotes and whatnot.
$status = apply_filters( 'the_content', $post->post_content );
// Strip tags and shorten.
$status = wp_trim_words( $status, 25, ' […]' );
// Prevent double-encoded entities.
$status = html_entity_decode( $status, ENT_QUOTES | ENT_HTML5, get_bloginfo( 'charset' ) );
<?php
add_action( 'init', function() {
add_shortcode( 'breadcrumbs', function() {
if ( ! is_page() ) {
return '';
}
global $post;
<?php
/**
* Our "API client," responsible for turning recent toots into WordPress posts.
*
* @package Import_From_Mastodon
*/
namespace Import_From_Mastodon;
/**
<?php
add_filter( 'pre_get_posts', function( $query ) {
if ( is_admin() ) {
return $query;
}
if ( is_feed() ) {
return $query;
}
<?php
/**
* Plugin Name: Webmention Widget
* Description: Add recent webmentions’ status to WordPress’ dashboard.
* Version: 0.1
* Author: Jan Boddez
* Author URI: https://jan.boddez.net/
* License: GNU General Public License v2 or later
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
*
<?php
add_action( 'webmention_post_send', function( $response, $source, $target, $post_id ) {
if ( is_wp_error( $response ) ) {
// Something went wrong.
error_log( 'Error trying to send webmention to ' . esc_url_raw( $target ) . ': ' . $response->get_error_message() );
} else {
error_log( 'Sent webmention to ' . esc_url_raw( $target ) . '; response code: ' . wp_remote_retrieve_response_code( $response ) );
}