Skip to content

Commit 2ed1534

Browse files
committed
move generate_id to utils class
1 parent ec24523 commit 2ed1534

File tree

2 files changed

+29
-27
lines changed

2 files changed

+29
-27
lines changed

includes/class-comment.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,4 +309,30 @@ public static function remote_comment_link( $comment_link, $comment ) {
309309

310310
return $comment_link;
311311
}
312+
313+
314+
/**
315+
* Generates an ActivityPub URI for a comment
316+
*
317+
* @param WP_Comment|int $comment A comment object or comment ID
318+
*
319+
* @return string ActivityPub URI for comment
320+
*/
321+
public static function generate_id( $comment ) {
322+
$comment = get_comment( $comment );
323+
324+
// show external comment ID if it exists
325+
$source_id = get_comment_meta( $comment->comment_ID, 'source_id', true );
326+
if ( ! empty( $source_id ) ) {
327+
return $source_id;
328+
}
329+
330+
// generate URI based on comment ID
331+
return \add_query_arg(
332+
array(
333+
'c' => $comment->comment_ID,
334+
),
335+
\trailingslashit( site_url() )
336+
);
337+
}
312338
}

includes/transformer/class-comment.php

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use WP_Comment;
55
use WP_Comment_Query;
66

7+
use Activitypub\Comment as Comment_Utils;
78
use Activitypub\Model\Blog_User;
89
use Activitypub\Collection\Users;
910
use Activitypub\Transformer\Base;
@@ -138,7 +139,7 @@ protected function get_in_reply_to() {
138139
} elseif ( ! empty( $comment_meta['source_url'][0] ) ) {
139140
$in_reply_to = $comment_meta['source_url'][0];
140141
} elseif ( ! empty( $parent_comment->user_id ) ) {
141-
$in_reply_to = $this->generate_id( $parent_comment );
142+
$in_reply_to = Comment_Utils::generate_id( $parent_comment );
142143
}
143144
} else {
144145
$in_reply_to = \get_permalink( $comment->comment_post_ID );
@@ -157,32 +158,7 @@ protected function get_in_reply_to() {
157158
*/
158159
protected function get_id() {
159160
$comment = $this->wp_object;
160-
return $this->generate_id( $comment );
161-
}
162-
163-
/**
164-
* Generates an ActivityPub URI for a comment
165-
*
166-
* @param WP_Comment|int $comment A comment object or comment ID
167-
*
168-
* @return string ActivityPub URI for comment
169-
*/
170-
protected function generate_id( $comment ) {
171-
$comment = get_comment( $comment );
172-
173-
// show external comment ID if it exists
174-
$source_id = get_comment_meta( $comment->comment_ID, 'source_id', true );
175-
if ( ! empty( $source_id ) ) {
176-
return $source_id;
177-
}
178-
179-
// generate URI based on comment ID
180-
return \add_query_arg(
181-
array(
182-
'c' => $comment->comment_ID,
183-
),
184-
\trailingslashit( site_url() )
185-
);
161+
return Comment_Utils::generate_id( $comment );
186162
}
187163

188164
/**

0 commit comments

Comments
 (0)