front-end reply inserts @mentions

This commit is contained in:
Django Doucet 2023-10-02 17:48:33 -06:00
parent 734235b500
commit f018432033
2 changed files with 21 additions and 1 deletions

View file

@ -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('');
});
}
} );

View file

@ -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()
*