re-add extract mentions filter

This commit is contained in:
Django Doucet 2023-10-27 14:17:53 -06:00
parent 9d1ba79788
commit 06be55b61a

View file

@ -15,6 +15,7 @@ class Mention {
*/ */
public static function init() { public static function init() {
\add_filter( 'the_content', array( self::class, 'the_content' ), 99, 2 ); \add_filter( 'the_content', array( self::class, 'the_content' ), 99, 2 );
\add_filter( 'activitypub_extract_mentions', array( self::class, 'extract_mentions' ), 99, 2 );
} }
/** /**
@ -146,4 +147,23 @@ class Mention {
return new WP_Error( 'activitypub_no_inbox', \__( 'No "Inbox" found', 'activitypub' ), $metadata ); return new WP_Error( 'activitypub_no_inbox', \__( 'No "Inbox" found', 'activitypub' ), $metadata );
} }
/**
* Extract the mentions from the post_content.
*
* @param array $mentions The already found mentions.
* @param string $post_content The post content.
*
* @return mixed The discovered mentions.
*/
public static function extract_mentions( $mentions, $post_content ) {
\preg_match_all( '/@' . ACTIVITYPUB_USERNAME_REGEXP . '/i', $post_content, $matches );
foreach ( $matches[0] as $match ) {
$link = Webfinger::resolve( $match );
if ( ! is_wp_error( $link ) ) {
$mentions[ $match ] = $link;
}
}
return $mentions;
}
} }