From 2ad9bf9148b957913c9e36e302cb728ce821d446 Mon Sep 17 00:00:00 2001 From: Django Date: Tue, 5 Sep 2023 00:48:50 -0600 Subject: [PATCH] Link remote comments to source url (#415) --- includes/class-activitypub.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/includes/class-activitypub.php b/includes/class-activitypub.php index c85bb3d..6ac860e 100644 --- a/includes/class-activitypub.php +++ b/includes/class-activitypub.php @@ -17,6 +17,7 @@ class Activitypub { \add_filter( 'template_include', array( self::class, 'render_json_template' ), 99 ); \add_filter( 'query_vars', array( self::class, 'add_query_vars' ) ); \add_filter( 'pre_get_avatar_data', array( self::class, 'pre_get_avatar_data' ), 11, 2 ); + \add_filter( 'get_comment_link', array( self::class, 'remote_comment_link' ), 11, 3 ); // Add support for ActivityPub to custom post types $post_types = \get_option( 'activitypub_support_post_types', array( 'post', 'page' ) ) ? \get_option( 'activitypub_support_post_types', array( 'post', 'page' ) ) : array(); @@ -179,6 +180,22 @@ class Activitypub { return \get_comment_meta( $comment->comment_ID, 'avatar_url', true ); } + /** + * Link remote comments to source url. + * + * @param string $comment_link + * @param object|WP_Comment $comment + * + * @return string $url + */ + public static function remote_comment_link( $comment_link, $comment ) { + $remote_comment_link = get_comment_meta( $comment->comment_ID, 'source_url', true ); + if ( $remote_comment_link ) { + $comment_link = esc_url( $remote_comment_link ); + } + return $comment_link; + } + /** * Store permalink in meta, to send delete Activity. *