Skip to content

Commit c958876

Browse files
authored
Comments: Never allow edit of federated comments (#1895)
1 parent c256f57 commit c958876

File tree

3 files changed

+23
-18
lines changed

3 files changed

+23
-18
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: fixed
3+
4+
Comments received from the Fediverse no longer show an Edit link in the comment list, despite not being editable.

includes/class-comment.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class Comment {
2323
public static function init() {
2424
self::register_comment_types();
2525

26+
\add_filter( 'map_meta_cap', array( self::class, 'map_meta_cap' ), 10, 4 );
2627
\add_filter( 'comment_reply_link', array( self::class, 'comment_reply_link' ), 10, 3 );
2728
\add_filter( 'comment_class', array( self::class, 'comment_class' ), 10, 3 );
2829
\add_filter( 'comment_feed_where', array( static::class, 'comment_feed_where' ) );
@@ -35,6 +36,24 @@ public static function init() {
3536
\add_filter( 'pre_wp_update_comment_count_now', array( static::class, 'pre_wp_update_comment_count_now' ), 10, 3 );
3637
}
3738

39+
/**
40+
* Remove edit capabilities for comments received via ActivityPub.
41+
*
42+
* @param array $caps Array of capabilities.
43+
* @param string $cap Capability name.
44+
* @param int $user_id User ID.
45+
* @param array $args Array of arguments.
46+
*
47+
* @return array Modified array of capabilities.
48+
*/
49+
public static function map_meta_cap( $caps, $cap, $user_id, $args ) {
50+
if ( 'edit_comment' === $cap && self::was_received( $args[0] ) ) {
51+
$caps[] = 'do_not_allow';
52+
}
53+
54+
return $caps;
55+
}
56+
3857
/**
3958
* Filter the comment reply link.
4059
*

includes/wp-admin/class-admin.php

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -253,24 +253,6 @@ public static function enqueue_scripts( $hook_suffix ) {
253253
* Disables the edit_comment capability for federated comments.
254254
*/
255255
public static function edit_comment() {
256-
// Disable the edit_comment capability for federated comments.
257-
\add_filter(
258-
'user_has_cap',
259-
function ( $all_caps, $caps, $arg ) {
260-
if ( 'edit_comment' !== $arg[0] ) {
261-
return $all_caps;
262-
}
263-
264-
if ( was_comment_received( $arg[2] ) ) {
265-
return false;
266-
}
267-
268-
return $all_caps;
269-
},
270-
1,
271-
3
272-
);
273-
274256
// phpcs:ignore WordPress.Security.NonceVerification
275257
$comment_id = \absint( $_GET['c'] ?? 0 );
276258
if ( Comment::was_received( $comment_id ) ) {

0 commit comments

Comments
 (0)