diff --git a/assets/js/activitypub-reply.js b/assets/js/activitypub-reply.js index 8894ec4..a845265 100644 --- a/assets/js/activitypub-reply.js +++ b/assets/js/activitypub-reply.js @@ -19,7 +19,6 @@ jQuery( function( $ ) { if ( $('body').hasClass('logged-in') && $('body').hasClass('single') ) { //Insert @mentions into comment content on reply $( '.comment-reply-link' ).on( 'click', function( event ) { - console.log( 'comment-reply-link', $(this) ) var recipients = $(this).attr('data-recipients') ? $(this).attr('data-recipients') + ' ' : ''; console.log( 'recipients', recipients ) setTimeout(function() { @@ -28,5 +27,9 @@ jQuery( function( $ ) { } }, 100); }) + //Clear @mentions from content on cancel + $('#cancel-comment-reply-link').on('click', function(){ + $('#respond #comment').val(''); + }); } } ); diff --git a/includes/class-comments.php b/includes/class-comments.php index a44ef8f..309616c 100644 --- a/includes/class-comments.php +++ b/includes/class-comments.php @@ -16,6 +16,7 @@ class Comments { \add_filter( 'comment_excerpt', array( self::class, 'comment_excerpt' ), 10, 3 ); \add_filter( 'comment_text', array( self::class, 'comment_content_filter' ), 10, 3 ); \add_filter( 'comment_post', array( self::class, 'postprocess_comment' ), 10, 3 ); + \add_filter( 'comment_reply_link', array( self::class, 'comment_reply_link' ), 10, 4 ); \add_action( 'edit_comment', array( self::class, 'edit_comment' ), 20, 2 ); //schedule_admin_comment_activity \add_action( 'transition_comment_status', array( self::class, 'schedule_comment_activity' ), 20, 3 ); } @@ -102,6 +103,22 @@ class Comments { } } + /** + * Add reply recipients to comment_reply_link + * + * https://developer.wordpress.org/reference/hooks/comment_reply_link/ + * @param string $comment_reply_link + * @param array $args + * @param WP_Comment $comment + * @param WP_Post $post + * @return $comment_reply_link + */ + public static function comment_reply_link( $comment_reply_link, $args, $comment, $post ) { + $recipients = \Activitypub\reply_recipients( $comment->comment_ID ); + $comment_reply_link = str_replace( "class='comment-reply-link'", "class='comment-reply-link' data-recipients='${recipients}'", $comment_reply_link ); + return $comment_reply_link; + } + /** * edit_comment() *