PluginProbe
ActivityPub / 7.8.2
ActivityPub v7.8.2
9.3.1 9.3.0 9.2.2 9.2.1 9.2.0 9.1.0 9.0.2 9.0.1 9.0.0 8.3.0 8.2.1 8.2.0 8.1.1 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.2.0 1.3.0 2.0.0 2.0.1 2.1.0 2.1.1 All 160 releases
← All changes | includes/class-comment.php +64 -280 9.2.07.8.2 View file →
@@ -7,9 +7,9 @@
7 7
8 8 namespace Activitypub;
9 9
10 10 use Activitypub\Collection\Actors;
11 -use Activitypub\Collection\Remote_Posts;
11 +use Activitypub\Collection\Posts;
12 12
13 13 /**
14 14 * ActivityPub Comment Class.
15 15 *
@@ -28,50 +28,16 @@
28 28 \add_filter( 'comment_class', array( self::class, 'comment_class' ), 10, 3 );
29 29 \add_filter( 'comment_feed_where', array( static::class, 'comment_feed_where' ) );
30 30 \add_filter( 'get_comment_link', array( self::class, 'remote_comment_link' ), 11, 2 );
31 31 \add_action( 'pre_get_comments', array( static::class, 'comment_query' ) );
32 - \add_filter( 'pre_comment_approved', array( static::class, 'pre_comment_approved' ), 11, 2 );
32 + \add_filter( 'pre_comment_approved', array( static::class, 'pre_comment_approved' ), 10, 2 );
33 33 \add_filter( 'get_avatar_comment_types', array( static::class, 'get_avatar_comment_types' ), 99 );
34 34 \add_action( 'update_option_activitypub_allow_likes', array( self::class, 'maybe_update_comment_counts' ), 10, 2 );
35 35 \add_action( 'update_option_activitypub_allow_reposts', array( self::class, 'maybe_update_comment_counts' ), 10, 2 );
36 - \add_filter( 'pre_wp_update_comment_count_now', array( static::class, 'pre_wp_update_comment_count_now' ), 5, 3 );
37 - \add_filter( 'get_comment_author', array( static::class, 'render_emoji' ), 10, 2 );
38 - \add_filter( 'comment_author', array( static::class, 'unescape_emoji' ), 20 ); // After esc_html().
39 - \add_filter( 'rest_comment_query', array( static::class, 'rest_comment_query' ) );
40 - \add_filter( 'comment_text', array( static::class, 'render_blocks' ), 5 ); // Before other filters.
36 + \add_filter( 'pre_wp_update_comment_count_now', array( static::class, 'pre_wp_update_comment_count_now' ), 10, 3 );
41 37 }
42 38
43 39 /**
44 - * Render blocks in comment content.
45 - *
46 - * Comments don't automatically parse blocks like posts do.
47 - * This filter applies do_blocks() to render activitypub/emoji
48 - * and activitypub/image blocks in comment content.
49 - *
50 - * @param string $content The comment content.
51 - *
52 - * @return string The content with blocks rendered.
53 - */
54 - public static function render_blocks( $content ) {
55 - if ( empty( $content ) || ! \str_contains( $content, '<!-- wp:activitypub/' ) ) {
56 - return $content;
57 - }
58 -
59 - $blocks = \parse_blocks( $content );
60 - $output = '';
61 -
62 - foreach ( $blocks as $block ) {
63 - if ( ! empty( $block['blockName'] ) && \str_starts_with( $block['blockName'], 'activitypub/' ) ) {
64 - $output .= \render_block( $block );
65 - } else {
66 - $output .= \serialize_block( $block );
67 - }
68 - }
69 -
70 - return $output;
71 - }
72 -
73 - /**
74 40 * Remove edit capabilities for comments received via ActivityPub.
75 41 *
76 42 * @param array $caps Array of capabilities.
77 43 * @param string $cap Capability name.
@@ -92,12 +58,10 @@
92 58
93 59 /**
94 60 * Filter the comment reply link.
95 61 *
96 - * Handles three cases for replies to fediverse comments:
97 - * 1. User can federate → show normal reply link
98 - * 2. User is logged in but can't federate → show warning (no reply link)
99 - * 3. User is not logged in → show remote reply block
62 + * We don't want to show the comment reply link for federated comments
63 + * if the user is disabled for federation.
100 64 *
101 65 * @param string $link The HTML markup for the comment reply link.
102 66 * @param array $args An array of arguments overriding the defaults.
103 67 * @param \WP_Comment $comment The object of the comment being replied.
@@ -108,42 +72,8 @@
108 72 if ( self::are_comments_allowed( $comment ) ) {
109 73 return $link;
110 74 }
111 75
112 - // Logged-in user without ActivityPub capability - show warning instead of reply link.
113 - if ( \is_user_logged_in() ) {
114 - $author = \esc_html( $comment->comment_author );
115 -
116 - $message = \sprintf(
117 - /* translators: %s: comment author name */
118 - \__( '%s is on the Fediverse. To reply to them, ask your administrator to enable ActivityPub for your account.', 'activitypub' ),
119 - $author
120 - );
121 -
122 - // Add link to users page if current user can edit users.
123 - if ( \current_user_can( 'edit_users' ) ) {
124 - $message = \sprintf(
125 - /* translators: 1: comment author name, 2: URL to the users management page */
126 - \__( '%1$s is on the Fediverse. To reply to them, <a href="%2$s">enable ActivityPub for your account</a>.', 'activitypub' ),
127 - $author,
128 - \esc_url( \admin_url( 'users.php' ) )
129 - );
130 - }
131 -
132 - $warning = \sprintf(
133 - '<p class="activitypub-reply-warning"><em>%s</em></p>',
134 - \wp_kses( $message, array( 'a' => array( 'href' => array() ) ) )
135 - );
136 -
137 - /**
138 - * Filters the warning message shown to logged-in users without ActivityPub capability.
139 - *
140 - * @param string $warning The warning HTML markup.
141 - * @param \WP_Comment $comment The comment being replied to.
142 - */
143 - return \apply_filters( 'activitypub_federation_warning', $warning, $comment );
144 - }
145 -
146 76 if ( ! \WP_Block_Type_Registry::get_instance()->is_registered( 'activitypub/remote-reply' ) ) {
147 77 \register_block_type_from_metadata( ACTIVITYPUB_PLUGIN_DIR . 'build/remote-reply' );
148 78 }
149 79
@@ -177,20 +107,19 @@
177 107 if ( ! self::was_received( $comment ) ) {
178 108 return true;
179 109 }
180 110
181 - $current_user = \get_current_user_id();
111 + $current_user = get_current_user_id();
182 112
183 113 if ( ! $current_user ) {
184 114 return false;
185 115 }
186 116
187 - if ( is_single_user() && \user_can( $current_user, 'activitypub' ) ) {
188 - // On a single user site, comments by users with the `activitypub` capability will be federated as the blog user.
117 + if ( is_single_user() && \user_can( $current_user, 'publish_posts' ) ) {
118 + // On a single user site, comments by users with the `publish_posts` capability will be federated as the blog user.
189 119 $current_user = Actors::BLOG_USER_ID;
190 120 }
191 121
192 - // User is not allowed to federate comments.
193 122 return user_can_activitypub( $current_user );
194 123 }
195 124
196 125 /**
@@ -289,9 +218,9 @@
289 218 return false;
290 219 }
291 220
292 221 if ( is_single_user() && \user_can( $user_id, 'activitypub' ) ) {
293 - // On a single user site, comments by users with the `activitypub` capability will be federated as the blog user.
222 + // On a single user site, comments by users with the `publish_posts` capability will be federated as the blog user.
294 223 $user_id = Actors::BLOG_USER_ID;
295 224 }
296 225
297 226 // User is not allowed to federate comments.
@@ -298,19 +227,8 @@
298 227 if ( ! user_can_activitypub( $user_id ) ) {
299 228 return false;
300 229 }
301 230
302 - /*
303 - * Do not federate brand-new comments on a post that is not federated itself
304 - * (e.g. a private post, a post switched to local visibility, or a non-ActivityPub
305 - * post type). This prevents leaking replies on content the post type's read rules
306 - * would otherwise protect. Comments that were already sent are allowed through so
307 - * their Update and Delete activities can still federate (and tear down remote copies).
308 - */
309 - if ( ! self::was_sent( $comment ) && ! is_post_federated( $comment->comment_post_ID ) ) {
310 - return false;
311 - }
312 -
313 231 // It is a comment to the post and can be federated.
314 232 if ( empty( $comment->comment_parent ) ) {
315 233 return true;
316 234 }
@@ -323,33 +241,22 @@
323 241
324 242 /**
325 243 * Examine a comment ID and look up an existing comment it represents.
326 244 *
327 - * @since 9.1.0 Added the `$args` parameter.
245 + * @param string $id ActivityPub object ID (usually a URL) to check.
328 246 *
329 - * @param string $id ActivityPub object ID (usually a URL) to check.
330 - * @param array $args Optional. Additional WP_Comment_Query arguments. Pass `array( 'status' => 'any' )`
331 - * to also match comments in spam or trash, which the default status excludes.
332 - *
333 247 * @return \WP_Comment|false Comment object, or false on failure.
334 248 */
335 - public static function object_id_to_comment( $id, $args = array() ) {
336 - $args = \wp_parse_args(
337 - $args,
249 + public static function object_id_to_comment( $id ) {
250 + $comment_query = new \WP_Comment_Query(
338 251 array(
339 - 'number' => 1,
340 - 'orderby' => 'comment_date',
341 - 'order' => 'DESC',
252 + 'meta_key' => 'source_id', // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
253 + 'meta_value' => $id, // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value
254 + 'orderby' => 'comment_date',
255 + 'order' => 'DESC',
342 256 )
343 257 );
344 258
345 - // Force the lookup key and full comment objects, so callers cannot break the return contract.
346 - $args['fields'] = 'all';
347 - $args['meta_key'] = 'source_id'; // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
348 - $args['meta_value'] = $id; // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value
349 -
350 - $comment_query = new \WP_Comment_Query( $args );
351 -
352 259 if ( ! $comment_query->comments ) {
353 260 return false;
354 261 }
355 262
@@ -403,9 +310,9 @@
403 310
404 311 $query = new \WP_Comment_Query();
405 312 $comments = $query->query( $args );
406 313
407 - if ( $comments && \is_array( $comments ) ) {
314 + if ( $comments && is_array( $comments ) ) {
408 315 return $comments[0]->comment_ID;
409 316 }
410 317
411 318 return null;
@@ -421,9 +328,9 @@
421 328 * @return string[] An array of classes.
422 329 */
423 330 public static function comment_class( $classes, $css_class, $comment_id ) {
424 331 // Check if ActivityPub comment.
425 - if ( 'activitypub' === \get_comment_meta( $comment_id, 'protocol', true ) ) {
332 + if ( 'activitypub' === get_comment_meta( $comment_id, 'protocol', true ) ) {
426 333 $classes[] = 'activitypub-comment';
427 334 }
428 335
429 336 return $classes;
@@ -452,11 +359,11 @@
452 359 if ( \in_array( $comment_type, $comment_types, true ) ) {
453 360 $where .= $wpdb->prepare( ' AND comment_type = %s', $comment_type );
454 361 } else {
455 362 $comment_types = \array_map( 'esc_sql', $comment_types );
456 - $placeholders = \implode( ', ', \array_fill( 0, \count( $comment_types ), '%s' ) );
363 + $placeholders = implode( ', ', array_fill( 0, count( $comment_types ), '%s' ) );
457 364 // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber, WordPress.DB.PreparedSQL.NotPrepared
458 - $where .= $wpdb->prepare( \sprintf( ' AND comment_type NOT IN (%s)', $placeholders ), ...$comment_types );
365 + $where .= $wpdb->prepare( sprintf( ' AND comment_type NOT IN (%s)', $placeholders ), ...$comment_types );
459 366 }
460 367
461 368 return $where;
462 369 }
@@ -586,9 +493,9 @@
586 493 $activity_type = \sanitize_key( $activity_type );
587 494 $comment_types = self::get_comment_types();
588 495
589 496 foreach ( $comment_types as $comment_type ) {
590 - if ( \in_array( $activity_type, $comment_type['activity_types'], true ) ) {
497 + if ( in_array( $activity_type, $comment_type['activity_types'], true ) ) {
591 498 return $comment_type;
592 499 }
593 500 }
594 501
@@ -602,9 +509,9 @@
602 509 */
603 510 public static function get_comment_types() {
604 511 global $activitypub_comment_types;
605 512
606 - return (array) $activitypub_comment_types;
513 + return $activitypub_comment_types;
607 514 }
608 515
609 516 /**
610 517 * Is this a registered comment type.
@@ -627,15 +534,15 @@
627 534 *
628 535 * @return array The registered custom comment type slugs.
629 536 */
630 537 public static function get_comment_type_slugs() {
631 - if ( ! \did_action( 'init' ) ) {
632 - \_doing_it_wrong( __METHOD__, 'This function should not be called before the init action has run. Comment types are only available after init.', '7.5.0' );
538 + if ( ! did_action( 'init' ) ) {
539 + _doing_it_wrong( __METHOD__, 'This function should not be called before the init action has run. Comment types are only available after init.', '7.5.0' );
633 540
634 541 return array();
635 542 }
636 543
637 - return \array_keys( self::get_comment_types() );
544 + return array_keys( self::get_comment_types() );
638 545 }
639 546
640 547 /**
641 548 * Get the custom comment type.
@@ -649,16 +556,16 @@
649 556 *
650 557 * @return array The comment type.
651 558 */
652 559 public static function get_comment_type( $type ) {
653 - $type = \strtolower( $type );
654 - $type = \sanitize_key( $type );
560 + $type = strtolower( $type );
561 + $type = sanitize_key( $type );
655 562
656 563 $comment_types = self::get_comment_types();
657 564 $type_array = array();
658 565
659 566 // Check array keys.
660 - if ( \in_array( $type, \array_keys( $comment_types ), true ) ) {
567 + if ( in_array( $type, array_keys( $comment_types ), true ) ) {
661 568 $type_array = $comment_types[ $type ];
662 569 }
663 570
664 571 /**
@@ -665,9 +572,9 @@
665 572 * Filter the comment type.
666 573 *
667 574 * @param array $type_array The comment type.
668 575 */
669 - return \apply_filters( "activitypub_comment_type_{$type}", $type_array );
576 + return apply_filters( "activitypub_comment_type_{$type}", $type_array );
670 577 }
671 578
672 579 /**
673 580 * Get a comment type attribute.
@@ -691,9 +598,9 @@
691 598 *
692 599 * @param mixed $value The value of the attribute.
693 600 * @param string $type The comment type.
694 601 */
695 - return \apply_filters( "activitypub_comment_type_{$attr}", $value, $type );
602 + return apply_filters( "activitypub_comment_type_{$attr}", $value, $type );
696 603 }
697 604
698 605 /**
699 606 * Register the comment types used by the ActivityPub plugin.
@@ -701,10 +608,10 @@
701 608 public static function register_comment_types() {
702 609 register_comment_type(
703 610 'repost',
704 611 array(
705 - 'label' => \__( 'Reposts', 'activitypub' ),
706 - 'singular' => \__( 'Repost', 'activitypub' ),
612 + 'label' => __( 'Reposts', 'activitypub' ),
613 + 'singular' => __( 'Repost', 'activitypub' ),
707 614 'description' => 'A repost (or Announce) is when a post appears in the timeline because someone else shared it, while still showing the original author as the source.',
708 615 'icon' => '♻️',
709 616 'class' => 'p-repost',
710 617 'type' => 'repost',
@@ -709,13 +616,13 @@
709 616 'class' => 'p-repost',
710 617 'type' => 'repost',
711 618 'collection' => 'reposts',
712 619 'activity_types' => array( 'announce' ),
713 - 'excerpt' => \html_entity_decode( \__( '&hellip; reposted this!', 'activitypub' ) ),
620 + 'excerpt' => html_entity_decode( \__( '&hellip; reposted this!', 'activitypub' ) ),
714 621 /* translators: %d: Number of reposts */
715 - 'count_single' => \_x( '%d repost', 'number of reposts', 'activitypub' ),
622 + 'count_single' => _x( '%d repost', 'number of reposts', 'activitypub' ),
716 623 /* translators: %d: Number of reposts */
717 - 'count_plural' => \_x( '%d reposts', 'number of reposts', 'activitypub' ),
624 + 'count_plural' => _x( '%d reposts', 'number of reposts', 'activitypub' ),
718 625 )
719 626 );
720 627
721 628 register_comment_type(
@@ -720,10 +627,10 @@
720 627
721 628 register_comment_type(
722 629 'like',
723 630 array(
724 - 'label' => \__( 'Likes', 'activitypub' ),
725 - 'singular' => \__( 'Like', 'activitypub' ),
631 + 'label' => __( 'Likes', 'activitypub' ),
632 + 'singular' => __( 'Like', 'activitypub' ),
726 633 'description' => 'A like is a small positive reaction that shows appreciation for a post without sharing it further.',
727 634 'icon' => '👍',
728 635 'class' => 'p-like',
729 636 'type' => 'like',
@@ -728,13 +635,13 @@
728 635 'class' => 'p-like',
729 636 'type' => 'like',
730 637 'collection' => 'likes',
731 638 'activity_types' => array( 'like' ),
732 - 'excerpt' => \html_entity_decode( \__( '&hellip; liked this!', 'activitypub' ) ),
639 + 'excerpt' => html_entity_decode( \__( '&hellip; liked this!', 'activitypub' ) ),
733 640 /* translators: %d: Number of likes */
734 - 'count_single' => \_x( '%d like', 'number of likes', 'activitypub' ),
641 + 'count_single' => _x( '%d like', 'number of likes', 'activitypub' ),
735 642 /* translators: %d: Number of likes */
736 - 'count_plural' => \_x( '%d likes', 'number of likes', 'activitypub' ),
643 + 'count_plural' => _x( '%d likes', 'number of likes', 'activitypub' ),
737 644 )
738 645 );
739 646
740 647 register_comment_type(
@@ -739,10 +646,10 @@
739 646
740 647 register_comment_type(
741 648 'quote',
742 649 array(
743 - 'label' => \__( 'Quotes', 'activitypub' ),
744 - 'singular' => \__( 'Quote', 'activitypub' ),
650 + 'label' => __( 'Quotes', 'activitypub' ),
651 + 'singular' => __( 'Quote', 'activitypub' ),
745 652 'description' => 'A quote is when a post is shared along with an added comment, so the original post appears together with the sharer&#8217;s own words.',
746 653 'icon' => '❞',
747 654 'class' => 'p-quote',
748 655 'type' => 'quote',
@@ -747,13 +654,13 @@
747 654 'class' => 'p-quote',
748 655 'type' => 'quote',
749 656 'collection' => 'quotes',
750 657 'activity_types' => array( 'quote' ),
751 - 'excerpt' => \html_entity_decode( \__( '&hellip; quoted this!', 'activitypub' ) ),
658 + 'excerpt' => html_entity_decode( \__( '&hellip; quoted this!', 'activitypub' ) ),
752 659 /* translators: %d: Number of quotes */
753 - 'count_single' => \_x( '%d quote', 'number of quotes', 'activitypub' ),
660 + 'count_single' => _x( '%d quote', 'number of quotes', 'activitypub' ),
754 661 /* translators: %d: Number of quotes */
755 - 'count_plural' => \_x( '%d quotes', 'number of quotes', 'activitypub' ),
662 + 'count_plural' => _x( '%d quotes', 'number of quotes', 'activitypub' ),
756 663 )
757 664 );
758 665 }
759 666
@@ -765,11 +672,11 @@
765 672 * @return array show avatars on Activities
766 673 */
767 674 public static function get_avatar_comment_types( $types ) {
768 675 $comment_types = self::get_comment_type_slugs();
769 - $types = \array_merge( $types, $comment_types );
676 + $types = array_merge( $types, $comment_types );
770 677
771 - return \array_unique( $types );
678 + return array_unique( $types );
772 679 }
773 680
774 681 /**
775 682 * Excludes likes and reposts from comment queries.
@@ -785,20 +692,20 @@
785 692 return;
786 693 }
787 694
788 695 // Do not exclude likes and reposts on ActivityPub requests.
789 - if ( \defined( 'ACTIVITYPUB_REQUEST' ) && ACTIVITYPUB_REQUEST ) {
696 + if ( defined( 'ACTIVITYPUB_REQUEST' ) && ACTIVITYPUB_REQUEST ) {
790 697 return;
791 698 }
792 699
793 - // Do not exclude likes and reposts on REST requests (handled by rest_comment_query).
700 + // Do not exclude likes and reposts on REST requests.
794 701 if ( \wp_is_serving_rest_request() ) {
795 702 return;
796 703 }
797 704
798 - // Filter post types for admin requests.
705 + // Do only exclude interactions of `ap_post` post type.
799 706 if ( \is_admin() ) {
800 - $query->query_vars['post_type'] = self::get_allowed_comment_post_types();
707 + $query->query_vars['post_type'] = array_diff( \get_post_types_by_support( 'comments' ), self::hide_for() );
801 708 return;
802 709 }
803 710
804 711 // Do not exclude likes and reposts on non-singular pages.
@@ -805,60 +712,18 @@
805 712 if ( ! \is_singular() ) {
806 713 return;
807 714 }
808 715
809 - // Do not exclude likes and reposts if the query is for specific types.
716 + // Do not exclude likes and reposts if the query is for comments.
810 717 if ( ! empty( $query->query_vars['type__in'] ) || ! empty( $query->query_vars['type'] ) ) {
811 718 return;
812 719 }
813 720
814 - // Do not exclude likes and reposts if the query is already excluding other comment types.
815 - if ( ! empty( $query->query_vars['type__not_in'] ) ) {
816 - return;
817 - }
818 -
819 721 // Exclude likes and reposts by the ActivityPub plugin.
820 722 $query->query_vars['type__not_in'] = self::get_comment_type_slugs();
821 723 }
822 724
823 725 /**
824 - * Filters comments in REST API requests.
825 - *
826 - * Excludes comments on ActivityPub post types and ActivityPub comment
827 - * types (likes, reposts) from the REST API.
828 - *
829 - * @param array $prepared_args Array of arguments for WP_Comment_Query.
830 - *
831 - * @return array Modified array of arguments.
832 - */
833 - public static function rest_comment_query( $prepared_args ) {
834 - // Exclude comments on ActivityPub post types.
835 - $prepared_args['post_type'] = self::get_allowed_comment_post_types();
836 -
837 - // Exclude ActivityPub comment types (likes, reposts) unless explicitly requested.
838 - if ( empty( $prepared_args['type'] ) && empty( $prepared_args['type__in'] ) ) {
839 - $prepared_args['type__not_in'] = self::get_comment_type_slugs();
840 - }
841 -
842 - return $prepared_args;
843 - }
844 -
845 - /**
846 - * Returns post types that should show comments (excluding hidden post types).
847 - *
848 - * @return array Array of post type names.
849 - */
850 - private static function get_allowed_comment_post_types() {
851 - $hide_for = self::hide_for();
852 -
853 - if ( empty( $hide_for ) ) {
854 - return \get_post_types_by_support( 'comments' );
855 - }
856 -
857 - return \array_diff( \get_post_types_by_support( 'comments' ), $hide_for );
858 - }
859 -
860 - /**
861 726 * Filter the comment status before it is set.
862 727 *
863 728 * @param int|string|\WP_Error $approved The approved comment status.
864 729 * @param array $comment_data The comment data.
@@ -865,14 +730,9 @@
865 730 *
866 731 * @return int|string|\WP_Error The approval status. 1, 0, 'spam', 'trash', or WP_Error.
867 732 */
868 733 public static function pre_comment_approved( $approved, $comment_data ) {
869 - /*
870 - * Only return early for already-approved comments, trash, or errors.
871 - * Don't short-circuit on 'spam' - we may want to override Akismet.
872 - * Respect 'trash' since it comes from the WordPress disallowed list.
873 - */
874 - if ( 1 === $approved || '1' === $approved || 'trash' === $approved || \is_wp_error( $approved ) ) {
734 + if ( $approved || \is_wp_error( $approved ) ) {
875 735 return $approved;
876 736 }
877 737
878 738 // Maybe auto-approve likes and reposts.
@@ -882,19 +742,8 @@
882 742 ) {
883 743 return 1;
884 744 }
885 745
886 - /*
887 - * Always auto-approve comments on remote posts (ap_post) since
888 - * they are not visible in the WP admin comment moderation screen.
889 - */
890 - $post_id = $comment_data['comment_post_ID'];
891 - $post = \get_post( $post_id );
892 -
893 - if ( $post && \in_array( $post->post_type, self::hide_for(), true ) ) {
894 - return 1;
895 - }
896 -
897 746 if ( '1' !== \get_option( 'comment_previously_approved' ) ) {
898 747 return $approved;
899 748 }
900 749
@@ -915,8 +764,15 @@
915 764 if ( 1 === (int) $ok_to_comment ) {
916 765 return 1;
917 766 }
918 767
768 + $post_id = $comment_data['comment_post_ID'];
769 + $post = \get_post( $post_id );
770 +
771 + if ( $post && in_array( $post->post_type, self::hide_for(), true ) ) {
772 + return 1;
773 + }
774 +
919 775 return $approved;
920 776 }
921 777
922 778 /**
@@ -943,38 +799,15 @@
943 799 * @return int|null The updated comment count, or null to use the default query.
944 800 */
945 801 public static function pre_wp_update_comment_count_now( $new_count, $old_count, $post_id ) {
946 802 if ( null === $new_count ) {
947 - $excluded_types = \array_filter( self::get_comment_type_slugs(), array( self::class, 'is_comment_type_enabled' ) );
803 + $excluded_types = array_filter( self::get_comment_type_slugs(), array( self::class, 'is_comment_type_enabled' ) );
948 804
949 805 if ( ! empty( $excluded_types ) ) {
950 - /*
951 - * Include 'note' type when Gutenberg's filter is registered, so a
952 - * single query excludes both ActivityPub and Gutenberg types.
953 - */
954 - if ( \has_filter( 'pre_wp_update_comment_count_now', 'gutenberg_exclude_notes_from_comment_count' ) ) {
955 - $excluded_types[] = 'note';
956 - }
957 -
958 - /**
959 - * Filters the comment types excluded from the comment count.
960 - *
961 - * Runs at priority 5 on `pre_wp_update_comment_count_now` so that
962 - * a single query can exclude types from multiple plugins. Other
963 - * plugins can hook here to add their own comment types.
964 - *
965 - * @since 8.0.0
966 - *
967 - * @param string[] $excluded_types The comment type slugs to exclude.
968 - * @param int $post_id The post ID.
969 - */
970 - $excluded_types = \apply_filters( 'activitypub_excluded_comment_types', $excluded_types, $post_id );
971 - $excluded_types = \array_unique( \array_filter( $excluded_types ) );
972 -
973 806 global $wpdb;
974 807
975 808 // phpcs:ignore WordPress.DB
976 - $new_count = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '1' AND comment_type NOT IN ('" . \implode( "','", $excluded_types ) . "')", $post_id ) );
809 + $new_count = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '1' AND comment_type NOT IN ('" . implode( "','", $excluded_types ) . "')", $post_id ) );
977 810 }
978 811 }
979 812
980 813 return $new_count;
@@ -986,9 +819,9 @@
986 819 * @param string $comment_type The comment type.
987 820 * @return bool True if the comment type is enabled.
988 821 */
989 822 public static function is_comment_type_enabled( $comment_type ) {
990 - return '1' === \get_option( "activitypub_allow_{$comment_type}s", '1' );
823 + return '1' === get_option( "activitypub_allow_{$comment_type}s", '1' );
991 824 }
992 825
993 826 /**
994 827 * Get post types to hide comments for in admin.
@@ -998,9 +831,9 @@
998 831 *
999 832 * @return string[] Array of post type names to hide comments for.
1000 833 */
1001 834 public static function hide_for() {
1002 - $post_types = array( Remote_Posts::POST_TYPE );
835 + $post_types = array( Posts::POST_TYPE );
1003 836
1004 837 /**
1005 838 * Filters the list of post types to hide comments for.
1006 839 *
@@ -1006,55 +839,6 @@
1006 839 *
1007 840 * @param string[] $post_types Array of post type names to hide comments for.
1008 841 */
1009 842 return \apply_filters( 'activitypub_hide_comments_for', $post_types );
1010 - }
1011 -
1012 - /**
1013 - * Render emoji in comment author name.
1014 - *
1015 - * Replaces emoji shortcodes with img tags on the get_comment_author filter.
1016 - * Emoji data is retrieved from the linked remote actor.
1017 - *
1018 - * @param string $author The comment author name.
1019 - * @param string $comment_id The comment ID as a numeric string.
1020 - *
1021 - * @return string The comment author name with rendered emoji.
1022 - */
1023 - public static function render_emoji( $author, $comment_id ) {
1024 - $remote_actor_id = \get_comment_meta( $comment_id, '_activitypub_remote_actor_id', true );
1025 -
1026 - if ( empty( $remote_actor_id ) ) {
1027 - return $author;
1028 - }
1029 -
1030 - $emoji_data = \get_post_meta( $remote_actor_id, '_activitypub_emoji', true );
1031 -
1032 - if ( empty( $emoji_data ) ) {
1033 - return $author;
1034 - }
1035 -
1036 - return Emoji::replace_from_json( $author, $emoji_data );
1037 - }
1038 -
1039 - /**
1040 - * Selectively unescape emoji images in comment author.
1041 - *
1042 - * This runs at priority 20 after WordPress's esc_html() filter on comment_author.
1043 - *
1044 - * @param string $author The comment author name (already escaped by WordPress).
1045 - *
1046 - * @return string The comment author name with emoji images unescaped.
1047 - */
1048 - public static function unescape_emoji( $author ) {
1049 - // Only attempt to unescape if there are emoji images present in the escaped string.
1050 - if ( false === \strpos( $author, 'class=&quot;emoji&quot;' ) ) {
1051 - return $author;
1052 - }
1053 -
1054 - // Decode entities so we can selectively restore emoji <img> tags.
1055 - $decoded = \html_entity_decode( $author, ENT_QUOTES | ENT_HTML5, 'UTF-8' );
1056 -
1057 - // Use strict KSES validation to only allow valid emoji img tags.
1058 - return \wp_kses( $decoded, Emoji::get_kses_allowed_html() );
1059 843 }
1060 844 }