PluginProbe
ActivityPub / 8.0.2
ActivityPub v8.0.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 +56 -82 9.2.08.0.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 *
@@ -112,9 +112,9 @@
112 112 // Logged-in user without ActivityPub capability - show warning instead of reply link.
113 113 if ( \is_user_logged_in() ) {
114 114 $author = \esc_html( $comment->comment_author );
115 115
116 - $message = \sprintf(
116 + $message = sprintf(
117 117 /* translators: %s: comment author name */
118 118 \__( '%s is on the Fediverse. To reply to them, ask your administrator to enable ActivityPub for your account.', 'activitypub' ),
119 119 $author
120 120 );
@@ -120,9 +120,9 @@
120 120 );
121 121
122 122 // Add link to users page if current user can edit users.
123 123 if ( \current_user_can( 'edit_users' ) ) {
124 - $message = \sprintf(
124 + $message = sprintf(
125 125 /* translators: 1: comment author name, 2: URL to the users management page */
126 126 \__( '%1$s is on the Fediverse. To reply to them, <a href="%2$s">enable ActivityPub for your account</a>.', 'activitypub' ),
127 127 $author,
128 128 \esc_url( \admin_url( 'users.php' ) )
@@ -128,9 +128,9 @@
128 128 \esc_url( \admin_url( 'users.php' ) )
129 129 );
130 130 }
131 131
132 - $warning = \sprintf(
132 + $warning = sprintf(
133 133 '<p class="activitypub-reply-warning"><em>%s</em></p>',
134 134 \wp_kses( $message, array( 'a' => array( 'href' => array() ) ) )
135 135 );
136 136
@@ -177,9 +177,9 @@
177 177 if ( ! self::was_received( $comment ) ) {
178 178 return true;
179 179 }
180 180
181 - $current_user = \get_current_user_id();
181 + $current_user = get_current_user_id();
182 182
183 183 if ( ! $current_user ) {
184 184 return false;
185 185 }
@@ -298,19 +298,8 @@
298 298 if ( ! user_can_activitypub( $user_id ) ) {
299 299 return false;
300 300 }
301 301
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 302 // It is a comment to the post and can be federated.
314 303 if ( empty( $comment->comment_parent ) ) {
315 304 return true;
316 305 }
@@ -323,33 +312,22 @@
323 312
324 313 /**
325 314 * Examine a comment ID and look up an existing comment it represents.
326 315 *
327 - * @since 9.1.0 Added the `$args` parameter.
316 + * @param string $id ActivityPub object ID (usually a URL) to check.
328 317 *
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 318 * @return \WP_Comment|false Comment object, or false on failure.
334 319 */
335 - public static function object_id_to_comment( $id, $args = array() ) {
336 - $args = \wp_parse_args(
337 - $args,
320 + public static function object_id_to_comment( $id ) {
321 + $comment_query = new \WP_Comment_Query(
338 322 array(
339 - 'number' => 1,
340 - 'orderby' => 'comment_date',
341 - 'order' => 'DESC',
323 + 'meta_key' => 'source_id', // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
324 + 'meta_value' => $id, // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value
325 + 'orderby' => 'comment_date',
326 + 'order' => 'DESC',
342 327 )
343 328 );
344 329
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 330 if ( ! $comment_query->comments ) {
353 331 return false;
354 332 }
355 333
@@ -403,9 +381,9 @@
403 381
404 382 $query = new \WP_Comment_Query();
405 383 $comments = $query->query( $args );
406 384
407 - if ( $comments && \is_array( $comments ) ) {
385 + if ( $comments && is_array( $comments ) ) {
408 386 return $comments[0]->comment_ID;
409 387 }
410 388
411 389 return null;
@@ -421,9 +399,9 @@
421 399 * @return string[] An array of classes.
422 400 */
423 401 public static function comment_class( $classes, $css_class, $comment_id ) {
424 402 // Check if ActivityPub comment.
425 - if ( 'activitypub' === \get_comment_meta( $comment_id, 'protocol', true ) ) {
403 + if ( 'activitypub' === get_comment_meta( $comment_id, 'protocol', true ) ) {
426 404 $classes[] = 'activitypub-comment';
427 405 }
428 406
429 407 return $classes;
@@ -452,11 +430,11 @@
452 430 if ( \in_array( $comment_type, $comment_types, true ) ) {
453 431 $where .= $wpdb->prepare( ' AND comment_type = %s', $comment_type );
454 432 } else {
455 433 $comment_types = \array_map( 'esc_sql', $comment_types );
456 - $placeholders = \implode( ', ', \array_fill( 0, \count( $comment_types ), '%s' ) );
434 + $placeholders = implode( ', ', array_fill( 0, count( $comment_types ), '%s' ) );
457 435 // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber, WordPress.DB.PreparedSQL.NotPrepared
458 - $where .= $wpdb->prepare( \sprintf( ' AND comment_type NOT IN (%s)', $placeholders ), ...$comment_types );
436 + $where .= $wpdb->prepare( sprintf( ' AND comment_type NOT IN (%s)', $placeholders ), ...$comment_types );
459 437 }
460 438
461 439 return $where;
462 440 }
@@ -586,9 +564,9 @@
586 564 $activity_type = \sanitize_key( $activity_type );
587 565 $comment_types = self::get_comment_types();
588 566
589 567 foreach ( $comment_types as $comment_type ) {
590 - if ( \in_array( $activity_type, $comment_type['activity_types'], true ) ) {
568 + if ( in_array( $activity_type, $comment_type['activity_types'], true ) ) {
591 569 return $comment_type;
592 570 }
593 571 }
594 572
@@ -602,9 +580,9 @@
602 580 */
603 581 public static function get_comment_types() {
604 582 global $activitypub_comment_types;
605 583
606 - return (array) $activitypub_comment_types;
584 + return $activitypub_comment_types;
607 585 }
608 586
609 587 /**
610 588 * Is this a registered comment type.
@@ -627,15 +605,15 @@
627 605 *
628 606 * @return array The registered custom comment type slugs.
629 607 */
630 608 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' );
609 + if ( ! did_action( 'init' ) ) {
610 + _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 611
634 612 return array();
635 613 }
636 614
637 - return \array_keys( self::get_comment_types() );
615 + return array_keys( self::get_comment_types() );
638 616 }
639 617
640 618 /**
641 619 * Get the custom comment type.
@@ -649,16 +627,16 @@
649 627 *
650 628 * @return array The comment type.
651 629 */
652 630 public static function get_comment_type( $type ) {
653 - $type = \strtolower( $type );
654 - $type = \sanitize_key( $type );
631 + $type = strtolower( $type );
632 + $type = sanitize_key( $type );
655 633
656 634 $comment_types = self::get_comment_types();
657 635 $type_array = array();
658 636
659 637 // Check array keys.
660 - if ( \in_array( $type, \array_keys( $comment_types ), true ) ) {
638 + if ( in_array( $type, array_keys( $comment_types ), true ) ) {
661 639 $type_array = $comment_types[ $type ];
662 640 }
663 641
664 642 /**
@@ -665,9 +643,9 @@
665 643 * Filter the comment type.
666 644 *
667 645 * @param array $type_array The comment type.
668 646 */
669 - return \apply_filters( "activitypub_comment_type_{$type}", $type_array );
647 + return apply_filters( "activitypub_comment_type_{$type}", $type_array );
670 648 }
671 649
672 650 /**
673 651 * Get a comment type attribute.
@@ -691,9 +669,9 @@
691 669 *
692 670 * @param mixed $value The value of the attribute.
693 671 * @param string $type The comment type.
694 672 */
695 - return \apply_filters( "activitypub_comment_type_{$attr}", $value, $type );
673 + return apply_filters( "activitypub_comment_type_{$attr}", $value, $type );
696 674 }
697 675
698 676 /**
699 677 * Register the comment types used by the ActivityPub plugin.
@@ -701,10 +679,10 @@
701 679 public static function register_comment_types() {
702 680 register_comment_type(
703 681 'repost',
704 682 array(
705 - 'label' => \__( 'Reposts', 'activitypub' ),
706 - 'singular' => \__( 'Repost', 'activitypub' ),
683 + 'label' => __( 'Reposts', 'activitypub' ),
684 + 'singular' => __( 'Repost', 'activitypub' ),
707 685 '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 686 'icon' => '♻️',
709 687 'class' => 'p-repost',
710 688 'type' => 'repost',
@@ -709,13 +687,13 @@
709 687 'class' => 'p-repost',
710 688 'type' => 'repost',
711 689 'collection' => 'reposts',
712 690 'activity_types' => array( 'announce' ),
713 - 'excerpt' => \html_entity_decode( \__( '&hellip; reposted this!', 'activitypub' ) ),
691 + 'excerpt' => html_entity_decode( \__( '&hellip; reposted this!', 'activitypub' ) ),
714 692 /* translators: %d: Number of reposts */
715 - 'count_single' => \_x( '%d repost', 'number of reposts', 'activitypub' ),
693 + 'count_single' => _x( '%d repost', 'number of reposts', 'activitypub' ),
716 694 /* translators: %d: Number of reposts */
717 - 'count_plural' => \_x( '%d reposts', 'number of reposts', 'activitypub' ),
695 + 'count_plural' => _x( '%d reposts', 'number of reposts', 'activitypub' ),
718 696 )
719 697 );
720 698
721 699 register_comment_type(
@@ -720,10 +698,10 @@
720 698
721 699 register_comment_type(
722 700 'like',
723 701 array(
724 - 'label' => \__( 'Likes', 'activitypub' ),
725 - 'singular' => \__( 'Like', 'activitypub' ),
702 + 'label' => __( 'Likes', 'activitypub' ),
703 + 'singular' => __( 'Like', 'activitypub' ),
726 704 'description' => 'A like is a small positive reaction that shows appreciation for a post without sharing it further.',
727 705 'icon' => '👍',
728 706 'class' => 'p-like',
729 707 'type' => 'like',
@@ -728,13 +706,13 @@
728 706 'class' => 'p-like',
729 707 'type' => 'like',
730 708 'collection' => 'likes',
731 709 'activity_types' => array( 'like' ),
732 - 'excerpt' => \html_entity_decode( \__( '&hellip; liked this!', 'activitypub' ) ),
710 + 'excerpt' => html_entity_decode( \__( '&hellip; liked this!', 'activitypub' ) ),
733 711 /* translators: %d: Number of likes */
734 - 'count_single' => \_x( '%d like', 'number of likes', 'activitypub' ),
712 + 'count_single' => _x( '%d like', 'number of likes', 'activitypub' ),
735 713 /* translators: %d: Number of likes */
736 - 'count_plural' => \_x( '%d likes', 'number of likes', 'activitypub' ),
714 + 'count_plural' => _x( '%d likes', 'number of likes', 'activitypub' ),
737 715 )
738 716 );
739 717
740 718 register_comment_type(
@@ -739,10 +717,10 @@
739 717
740 718 register_comment_type(
741 719 'quote',
742 720 array(
743 - 'label' => \__( 'Quotes', 'activitypub' ),
744 - 'singular' => \__( 'Quote', 'activitypub' ),
721 + 'label' => __( 'Quotes', 'activitypub' ),
722 + 'singular' => __( 'Quote', 'activitypub' ),
745 723 '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 724 'icon' => '❞',
747 725 'class' => 'p-quote',
748 726 'type' => 'quote',
@@ -747,13 +725,13 @@
747 725 'class' => 'p-quote',
748 726 'type' => 'quote',
749 727 'collection' => 'quotes',
750 728 'activity_types' => array( 'quote' ),
751 - 'excerpt' => \html_entity_decode( \__( '&hellip; quoted this!', 'activitypub' ) ),
729 + 'excerpt' => html_entity_decode( \__( '&hellip; quoted this!', 'activitypub' ) ),
752 730 /* translators: %d: Number of quotes */
753 - 'count_single' => \_x( '%d quote', 'number of quotes', 'activitypub' ),
731 + 'count_single' => _x( '%d quote', 'number of quotes', 'activitypub' ),
754 732 /* translators: %d: Number of quotes */
755 - 'count_plural' => \_x( '%d quotes', 'number of quotes', 'activitypub' ),
733 + 'count_plural' => _x( '%d quotes', 'number of quotes', 'activitypub' ),
756 734 )
757 735 );
758 736 }
759 737
@@ -765,11 +743,11 @@
765 743 * @return array show avatars on Activities
766 744 */
767 745 public static function get_avatar_comment_types( $types ) {
768 746 $comment_types = self::get_comment_type_slugs();
769 - $types = \array_merge( $types, $comment_types );
747 + $types = array_merge( $types, $comment_types );
770 748
771 - return \array_unique( $types );
749 + return array_unique( $types );
772 750 }
773 751
774 752 /**
775 753 * Excludes likes and reposts from comment queries.
@@ -785,9 +763,9 @@
785 763 return;
786 764 }
787 765
788 766 // Do not exclude likes and reposts on ActivityPub requests.
789 - if ( \defined( 'ACTIVITYPUB_REQUEST' ) && ACTIVITYPUB_REQUEST ) {
767 + if ( defined( 'ACTIVITYPUB_REQUEST' ) && ACTIVITYPUB_REQUEST ) {
790 768 return;
791 769 }
792 770
793 771 // Do not exclude likes and reposts on REST requests (handled by rest_comment_query).
@@ -882,19 +860,8 @@
882 860 ) {
883 861 return 1;
884 862 }
885 863
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 864 if ( '1' !== \get_option( 'comment_previously_approved' ) ) {
898 865 return $approved;
899 866 }
900 867
@@ -915,8 +882,15 @@
915 882 if ( 1 === (int) $ok_to_comment ) {
916 883 return 1;
917 884 }
918 885
886 + $post_id = $comment_data['comment_post_ID'];
887 + $post = \get_post( $post_id );
888 +
889 + if ( $post && in_array( $post->post_type, self::hide_for(), true ) ) {
890 + return 1;
891 + }
892 +
919 893 return $approved;
920 894 }
921 895
922 896 /**
@@ -943,9 +917,9 @@
943 917 * @return int|null The updated comment count, or null to use the default query.
944 918 */
945 919 public static function pre_wp_update_comment_count_now( $new_count, $old_count, $post_id ) {
946 920 if ( null === $new_count ) {
947 - $excluded_types = \array_filter( self::get_comment_type_slugs(), array( self::class, 'is_comment_type_enabled' ) );
921 + $excluded_types = array_filter( self::get_comment_type_slugs(), array( self::class, 'is_comment_type_enabled' ) );
948 922
949 923 if ( ! empty( $excluded_types ) ) {
950 924 /*
951 925 * Include 'note' type when Gutenberg's filter is registered, so a
@@ -967,14 +941,14 @@
967 941 * @param string[] $excluded_types The comment type slugs to exclude.
968 942 * @param int $post_id The post ID.
969 943 */
970 944 $excluded_types = \apply_filters( 'activitypub_excluded_comment_types', $excluded_types, $post_id );
971 - $excluded_types = \array_unique( \array_filter( $excluded_types ) );
945 + $excluded_types = array_unique( array_filter( $excluded_types ) );
972 946
973 947 global $wpdb;
974 948
975 949 // 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 ) );
950 + $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 951 }
978 952 }
979 953
980 954 return $new_count;
@@ -986,9 +960,9 @@
986 960 * @param string $comment_type The comment type.
987 961 * @return bool True if the comment type is enabled.
988 962 */
989 963 public static function is_comment_type_enabled( $comment_type ) {
990 - return '1' === \get_option( "activitypub_allow_{$comment_type}s", '1' );
964 + return '1' === get_option( "activitypub_allow_{$comment_type}s", '1' );
991 965 }
992 966
993 967 /**
994 968 * Get post types to hide comments for in admin.
@@ -998,9 +972,9 @@
998 972 *
999 973 * @return string[] Array of post type names to hide comments for.
1000 974 */
1001 975 public static function hide_for() {
1002 - $post_types = array( Remote_Posts::POST_TYPE );
976 + $post_types = array( Posts::POST_TYPE );
1003 977
1004 978 /**
1005 979 * Filters the list of post types to hide comments for.
1006 980 *