@@ -506,6 +506,27 @@ public static function enqueue_scripts() {
506506 }
507507 }
508508
509+ /**
510+ * Get the comment type by activity type.
511+ *
512+ * @param string $activity_type The activity type.
513+ *
514+ * @return array|null The comment type.
515+ */
516+ public static function get_comment_type_by_activity_type ( $ activity_type ) {
517+ $ activity_type = \strtolower ( $ activity_type );
518+ $ activity_type = \sanitize_key ( $ activity_type );
519+ $ comment_types = self ::get_comment_types ();
520+
521+ foreach ( $ comment_types as $ comment_type ) {
522+ if ( in_array ( $ activity_type , $ comment_type ['activity_types ' ], true ) ) {
523+ return $ comment_type ;
524+ }
525+ }
526+
527+ return null ;
528+ }
529+
509530 /**
510531 * Return the registered custom comment types.
511532 *
@@ -520,23 +541,39 @@ public static function get_comment_types() {
520541 /**
521542 * Is this a registered comment type.
522543 *
523- * @param string $slug The name of the type.
544+ * @param string $slug The slug of the type.
545+ *
524546 * @return boolean True if registered.
525547 */
526548 public static function is_registered_comment_type ( $ slug ) {
527- $ slug = strtolower ( $ slug );
528- $ slug = sanitize_key ( $ slug );
549+ $ slug = \ strtolower ( $ slug );
550+ $ slug = \ sanitize_key ( $ slug );
529551
530- return in_array ( $ slug , array_keys ( self ::get_comment_types () ), true );
552+ $ comment_types = self ::get_comment_types ();
553+
554+ return isset ( $ comment_types [ $ slug ] );
555+ }
556+
557+ /**
558+ * Return the registered custom comment type slugs.
559+ *
560+ * @return array The registered custom comment type slugs.
561+ */
562+ public static function get_comment_type_slugs () {
563+ return array_keys ( self ::get_comment_types () );
531564 }
532565
533566 /**
534- * Return the registered custom comment types names.
567+ * Return the registered custom comment type slugs.
568+ *
569+ * @deprecated 4.5.0 Use get_comment_type_slugs instead.
535570 *
536- * @return array The registered custom comment type names .
571+ * @return array The registered custom comment type slugs .
537572 */
538573 public static function get_comment_type_names () {
539- return array_values ( wp_list_pluck ( self ::get_comment_types (), 'type ' ) );
574+ _deprecated_function ( __METHOD__ , '4.5.0 ' , 'get_comment_type_slugs ' );
575+
576+ return self ::get_comment_type_slugs ();
540577 }
541578
542579 /**
@@ -552,22 +589,15 @@ public static function get_comment_type_names() {
552589 * @return array The comment type.
553590 */
554591 public static function get_comment_type ( $ type ) {
555- $ type = strtolower ( $ type );
556- $ type = sanitize_key ( $ type );
557- $ types = self ::get_comment_types ();
592+ $ type = strtolower ( $ type );
593+ $ type = sanitize_key ( $ type );
558594
559- $ type_array = array ();
595+ $ comment_types = self ::get_comment_types ();
596+ $ type_array = array ();
560597
561598 // Check array keys.
562- if ( in_array ( $ type , array_keys ( $ types ), true ) ) {
563- $ type_array = $ types [ $ type ];
564- } else { // Fall back to type attribute.
565- foreach ( $ types as $ item ) {
566- if ( $ type === $ item ['type ' ] ) {
567- $ type_array = $ item ;
568- break ;
569- }
570- }
599+ if ( in_array ( $ type , array_keys ( $ comment_types ), true ) ) {
600+ $ type_array = $ comment_types [ $ type ];
571601 }
572602
573603 /**
@@ -609,28 +639,30 @@ public static function get_comment_type_attr( $type, $attr ) {
609639 */
610640 public static function register_comment_types () {
611641 register_comment_type (
612- 'announce ' ,
642+ 'repost ' ,
613643 array (
614- 'label ' => __ ( 'Reposts ' , 'activitypub ' ),
615- 'singular ' => __ ( 'Repost ' , 'activitypub ' ),
616- 'description ' => __ ( 'A repost on the indieweb is a post that is purely a 100% re-publication of another (typically someone else \'s) post. ' , 'activitypub ' ),
617- 'icon ' => '♻️ ' ,
618- 'class ' => 'p-repost ' ,
619- 'type ' => 'repost ' ,
620- 'excerpt ' => __ ( '… reposted this! ' , 'activitypub ' ),
644+ 'label ' => __ ( 'Reposts ' , 'activitypub ' ),
645+ 'singular ' => __ ( 'Repost ' , 'activitypub ' ),
646+ 'description ' => __ ( 'A repost on the indieweb is a post that is purely a 100% re-publication of another (typically someone else \'s) post. ' , 'activitypub ' ),
647+ 'icon ' => '♻️ ' ,
648+ 'class ' => 'p-repost ' ,
649+ 'type ' => 'repost ' ,
650+ 'activity_types ' => array ( 'announce ' ),
651+ 'excerpt ' => __ ( '… reposted this! ' , 'activitypub ' ),
621652 )
622653 );
623654
624655 register_comment_type (
625656 'like ' ,
626657 array (
627- 'label ' => __ ( 'Likes ' , 'activitypub ' ),
628- 'singular ' => __ ( 'Like ' , 'activitypub ' ),
629- 'description ' => __ ( 'A like is a popular webaction button and in some cases post type on various silos such as Facebook and Instagram. ' , 'activitypub ' ),
630- 'icon ' => '👍 ' ,
631- 'class ' => 'p-like ' ,
632- 'type ' => 'like ' ,
633- 'excerpt ' => __ ( '… liked this! ' , 'activitypub ' ),
658+ 'label ' => __ ( 'Likes ' , 'activitypub ' ),
659+ 'singular ' => __ ( 'Like ' , 'activitypub ' ),
660+ 'description ' => __ ( 'A like is a popular webaction button and in some cases post type on various silos such as Facebook and Instagram. ' , 'activitypub ' ),
661+ 'icon ' => '👍 ' ,
662+ 'class ' => 'p-like ' ,
663+ 'type ' => 'like ' ,
664+ 'activity_types ' => array ( 'like ' ),
665+ 'excerpt ' => __ ( '… liked this! ' , 'activitypub ' ),
634666 )
635667 );
636668 }
@@ -643,7 +675,7 @@ public static function register_comment_types() {
643675 * @return array show avatars on Activities
644676 */
645677 public static function get_avatar_comment_types ( $ types ) {
646- $ comment_types = self ::get_comment_type_names ();
678+ $ comment_types = self ::get_comment_type_slugs ();
647679 $ types = array_merge ( $ types , $ comment_types );
648680
649681 return array_unique ( $ types );
@@ -672,7 +704,7 @@ public static function comment_query( $query ) {
672704 }
673705
674706 // Exclude likes and reposts by the ActivityPub plugin.
675- $ query ->query_vars ['type__not_in ' ] = self ::get_comment_type_names ();
707+ $ query ->query_vars ['type__not_in ' ] = self ::get_comment_type_slugs ();
676708 }
677709
678710 /**
@@ -726,7 +758,7 @@ public static function pre_wp_update_comment_count_now( $new_count, $old_count,
726758 if ( null === $ new_count ) {
727759 global $ wpdb ;
728760
729- $ excluded_types = self ::get_comment_type_names ();
761+ $ excluded_types = self ::get_comment_type_slugs ();
730762
731763 // phpcs:ignore WordPress.DB
732764 $ 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 ) );
0 commit comments