Skip to content

Instantly share code, notes, and snippets.

View janboddez's full-sized avatar

Jan Boddez janboddez

View GitHub Profile
<?php
// Always share asides, even if their checkbox is disabled. So if you had the
// plugin's "opt in" option enabled, this would share all asides, plus whatever
// posts (regardless of their format) have sharing enabled explicitly.
add_filter( 'share_on_mastodon_enabled', function ( $is_enabled, $post_id ) {
if ( 'aside' === get_post_format( $post_id ) ) {
return true;
}
@janboddez
janboddez / nginx
Last active January 19, 2024 22:23
upstream php_fpm {
server unix:/run/php/php8.1-fpm.sock;
keepalive 10;
# Equal to PHP's `pm.max_requests`
keepalive_requests 500;
}
##
<?php
// Prevent direct access.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
add_filter( 'share_on_mastodon_excerpt_length', function() {
return 400; // Or whatever number works for you.
} );
<?php
// Prevent direct access.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
add_filter( 'import_from_mastodon_post_content', function( $content, $status ) {
// The plugin, by default, leaves hyperlinks in. This removes them.
return wp_kses(
<?php
add_filter( 'robots_txt', function( $output, $public ) {
$output = str_replace( 'Sitemap:', "User-agent: GPTBot\nDisallow: /\n\nSitemap:", $output );
return $output;
}, 10, 2 );
<?php
// Force re-approval of updated comments.
add_action( 'activitypub_handled_update', function( $activity, $second_param, $state, $reaction ) {
/** @todo: Send an email or something, because if you get quite a few of these, it's impossible to keep up. */
if ( $reaction instanceof \WP_Comment ) {
wp_set_comment_status( $reaction, 'hold' );
wp_notify_moderator( $reaction->comment_ID );
}
}, 99, 4 );
<?php
/**
* Modify likes' URLs, and add tagging.
*/
add_action( 'register_post_type_args', function( $args, $post_type ) {
if ( 'indieblocks_like' === $post_type ){
$args['rewrite']['slug'] = 'bookmarks'; // The new slug.
}
<?php
add_filter( 'http_request_host_is_external', '__return_true' );
<?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;
}