@@ -506,6 +506,27 @@ public static function enqueue_scripts() {
506
506
}
507
507
}
508
508
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
+
509
530
/**
510
531
* Return the registered custom comment types.
511
532
*
@@ -520,23 +541,39 @@ public static function get_comment_types() {
520
541
/**
521
542
* Is this a registered comment type.
522
543
*
523
- * @param string $slug The name of the type.
544
+ * @param string $slug The slug of the type.
545
+ *
524
546
* @return boolean True if registered.
525
547
*/
526
548
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 );
529
551
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 () );
531
564
}
532
565
533
566
/**
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.
535
570
*
536
- * @return array The registered custom comment type names .
571
+ * @return array The registered custom comment type slugs .
537
572
*/
538
573
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 ();
540
577
}
541
578
542
579
/**
@@ -552,22 +589,15 @@ public static function get_comment_type_names() {
552
589
* @return array The comment type.
553
590
*/
554
591
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 );
558
594
559
- $ type_array = array ();
595
+ $ comment_types = self ::get_comment_types ();
596
+ $ type_array = array ();
560
597
561
598
// 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 ];
571
601
}
572
602
573
603
/**
@@ -609,28 +639,30 @@ public static function get_comment_type_attr( $type, $attr ) {
609
639
*/
610
640
public static function register_comment_types () {
611
641
register_comment_type (
612
- 'announce ' ,
642
+ 'repost ' ,
613
643
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 ' ),
621
652
)
622
653
);
623
654
624
655
register_comment_type (
625
656
'like ' ,
626
657
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 ' ),
634
666
)
635
667
);
636
668
}
@@ -643,7 +675,7 @@ public static function register_comment_types() {
643
675
* @return array show avatars on Activities
644
676
*/
645
677
public static function get_avatar_comment_types ( $ types ) {
646
- $ comment_types = self ::get_comment_type_names ();
678
+ $ comment_types = self ::get_comment_type_slugs ();
647
679
$ types = array_merge ( $ types , $ comment_types );
648
680
649
681
return array_unique ( $ types );
@@ -672,7 +704,7 @@ public static function comment_query( $query ) {
672
704
}
673
705
674
706
// 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 ();
676
708
}
677
709
678
710
/**
@@ -726,7 +758,7 @@ public static function pre_wp_update_comment_count_now( $new_count, $old_count,
726
758
if ( null === $ new_count ) {
727
759
global $ wpdb ;
728
760
729
- $ excluded_types = self ::get_comment_type_names ();
761
+ $ excluded_types = self ::get_comment_type_slugs ();
730
762
731
763
// phpcs:ignore WordPress.DB
732
764
$ 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