Last active
October 15, 2023 07:55
-
-
Save janboddez/6851197fa3b2a416fb64070098e7526f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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( | |
$content, | |
array( | |
'br' => array(), | |
'p' => array(), | |
) | |
); | |
}, 10, 2 ); | |
add_action( 'import_from_mastodon_after_attachments', function( $post_id, $status ) { | |
// Unset post thumbnail. | |
delete_post_thumbnail( $post_id ); | |
// Get all uploaded images. | |
$attachments = get_attached_media( 'image', $post_id ); | |
if ( ! empty( $attachments ) ) { | |
$post = get_post( $post_id ); | |
$content = $post->post_content; | |
// Update post content. Classic editor only! | |
foreach ( $attachments as $attachment ) { | |
$content .= "\n\n" . wp_get_attachment_image( $attachment->ID, 'large' ); | |
} | |
wp_update_post( wp_slash( array( | |
'ID' => $post_id, | |
'post_content' => $content, | |
) ) ); | |
} | |
}, 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment