Skip to content

Instantly share code, notes, and snippets.

View janboddez's full-sized avatar

Jan Boddez janboddez

View GitHub Profile
<?php
add_action( 'transition_post_status', function ( $new_status, $old_status, $post ) { // phpcs:ignore PEAR.Functions.FunctionCallSignature.ContentAfterOpenBracket,PEAR.Functions.FunctionCallSignature.MultipleArguments
if ( 'publish' !== $new_status || 'publish' !== $old_status ) {
// Run only on when the post is public, or was public.
return;
}
// $hash = get_transient( "activitypub:sent:post:{$post->ID}" );
$hash = get_post_meta( $post->ID, '_activitypub_sent_hash', true );
<?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' );