pfefferle / wordpress-webmention

A Webmention plugin for WordPress
https://wordpress.org/plugins/webmention/
MIT License
116 stars 31 forks source link

Select type of WebMention to allow #343

Open edent opened 1 year ago

edent commented 1 year ago

As discussed in https://github.com/snarfed/bridgy/issues/1347

Yesterday I posted a link to my blog on Mastodon. This morning I work up to: 139 comments

Nearly all of them were likes and reposts: Screenshot of lots of comments

What would I need to do to change the plugin so it ignored reposts & likes?

Thanks!

edent commented 1 year ago

The comment gets saved at:

https://github.com/pfefferle/wordpress-webmention/blob/3fd2dec6c0e347484be65c15269f83f6ae6651b5/includes/class-webmention-receiver.php#L362

So I need a way to (manually) see if $commentdata is a reply, repost, like etc.

I assume that'll be $commentdata['comment_meta']['semantic_linkbacks_type'] ?

edent commented 1 year ago

In V5, the saving of the WebMention happens in:

https://github.com/pfefferle/wordpress-webmention/blob/d4bb5fb09f4622ea8d3e705862ab115b30b359ac/includes/class-receiver.php#L333

So the logic to delete certain types of WebMention could happen there. Although it might be easier / more efficient to do it at the top of the function:

https://github.com/pfefferle/wordpress-webmention/blob/d4bb5fb09f4622ea8d3e705862ab115b30b359ac/includes/class-receiver.php#L207

edent commented 1 year ago

There are now specific comment types - so should be easier to filter. Screenshot showing comment types as repost and like.

edent commented 1 year ago

Is there a way to use the 5.1.2 filtering to remove these messages? I've just received 200 "Bridgy Response" mentions which I need to delete.

edent commented 1 year ago

I've added this to my theme's functions.php file:

//  Remove Bridgy likes and reposts
add_action( 'comment_post', 'check_comment_content', 10, 2 );
function check_comment_content( $comment_id, $comment_approved ) {
    $comment = get_comment( $comment_id );
    // Check if the comment is a like or repost
    if ( $comment->comment_type == "like" || $comment->comment_type == "repost" ) {
        // Set the comment status to 'trash'
        wp_delete_comment( $comment_id );
    }
}