Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
185 changes: 115 additions & 70 deletions connectors/comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,42 @@ public static function get_context_labels() {
);
}

/**
* Return translated comment type labels
*
* @return array Comment type label translations
*/
public static function get_comment_type_labels() {
return apply_filters(
'wp_stream_comment_type_labels',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lukecarbis Nice idea.

array(
'comment' => __( 'Comment', 'default' ),
'trackback' => __( 'Trackback', 'default' ),
'pingback' => __( 'Pingback', 'default' ),
)
);
}

/**
* Return the comment type label for a given comment ID
*
* @param int $comment_id ID of the comment
* @return string The comment type label
*/
public static function get_comment_type_label( $comment_id ) {
$comment_type = get_comment_type( $comment_id );

if ( empty( $comment_type ) ) {
$comment_type = 'comment';
}

$comment_type_labels = self::get_comment_type_labels();

$label = isset( $comment_type_labels[ $comment_type ] ) ? $comment_type_labels[ $comment_type ] : $comment_type;

return $label;
}

/**
* Add action links to Stream drop row in admin list screen
*
Expand Down Expand Up @@ -189,30 +225,31 @@ public static function callback_wp_insert_comment( $comment_id, $comment ) {
$post_type = get_post_type( $post_id );
$post_title = ( $post = get_post( $post_id ) ) ? "\"$post->post_title\"" : __( 'a post', 'stream' );
$comment_status = ( 1 == $comment->comment_approved ) ? __( 'approved automatically', 'stream' ) : __( 'pending approval', 'stream' );
$comment_type = mb_strtolower( self::get_comment_type_label( $comment_id ) );

if ( $comment->comment_parent ) {
$parent_user_id = get_comment_author( $comment->comment_parent, 'id' );
$parent_user_name = get_comment_author( $comment->comment_parent, 'name' );

self::log(
_x(
'Reply to %1$s\'s comment by %2$s on %3$s %4$s',
"1: Parent comment's author, 2: Comment author, 3: Post title, 4: Comment status",
'Reply to %1$s\'s %5$s by %2$s on %3$s %4$s',
"1: Parent comment's author, 2: Comment author, 3: Post title, 4: Comment status, 5: Comment type",
'stream'
),
compact( 'parent_user_name', 'user_name', 'post_title', 'comment_status', 'post_id', 'parent_user_id' ),
compact( 'parent_user_name', 'user_name', 'post_title', 'comment_status', 'comment_type', 'post_id', 'parent_user_id' ),
$comment_id,
array( $post_type => 'replied' ),
$user_id
);
} else {
self::log(
_x(
'New comment by %1$s on %2$s %3$s',
'1: Comment author, 2: Post title 3: Comment status',
'New %4$s by %1$s on %2$s %3$s',
'1: Comment author, 2: Post title 3: Comment status, 4: Comment type',
'stream'
),
compact( 'user_name', 'post_title', 'comment_status', 'post_id' ),
compact( 'user_name', 'post_title', 'comment_status', 'comment_type', 'post_id' ),
$comment_id,
array( $post_type => 'created' ),
$user_id
Expand All @@ -232,19 +269,20 @@ public static function callback_edit_comment( $comment_id ) {
return;
}

$user_id = self::get_comment_author( $comment, 'id' );
$user_name = self::get_comment_author( $comment, 'name' );
$post_id = $comment->comment_post_ID;
$post_type = get_post_type( $post_id );
$post_title = ( $post = get_post( $post_id ) ) ? "\"$post->post_title\"" : __( 'a post', 'stream' );
$user_id = self::get_comment_author( $comment, 'id' );
$user_name = self::get_comment_author( $comment, 'name' );
$post_id = $comment->comment_post_ID;
$post_type = get_post_type( $post_id );
$post_title = ( $post = get_post( $post_id ) ) ? "\"$post->post_title\"" : __( 'a post', 'stream' );
$comment_type = mb_strtolower( self::get_comment_type_label( $comment_id ) );

self::log(
_x(
'%1$s\'s comment on %2$s edited',
'1: Comment author, 2: Post title',
'%1$s\'s %3$s on %2$s edited',
'1: Comment author, 2: Post title, 3: Comment type',
'stream'
),
compact( 'user_name', 'post_title', 'post_id', 'user_id' ),
compact( 'user_name', 'post_title', 'comment_type', 'post_id', 'user_id' ),
$comment_id,
array( $post_type => 'edited' )
);
Expand All @@ -262,19 +300,20 @@ public static function callback_delete_comment( $comment_id ) {
return;
}

$user_id = self::get_comment_author( $comment, 'id' );
$user_name = self::get_comment_author( $comment, 'name' );
$post_id = $comment->comment_post_ID;
$post_type = get_post_type( $post_id );
$post_title = ( $post = get_post( $post_id ) ) ? "\"$post->post_title\"" : __( 'a post', 'stream' );
$user_id = self::get_comment_author( $comment, 'id' );
$user_name = self::get_comment_author( $comment, 'name' );
$post_id = $comment->comment_post_ID;
$post_type = get_post_type( $post_id );
$post_title = ( $post = get_post( $post_id ) ) ? "\"$post->post_title\"" : __( 'a post', 'stream' );
$comment_type = mb_strtolower( self::get_comment_type_label( $comment_id ) );

self::log(
_x(
'%1$s\'s comment on %2$s deleted permanently',
'1: Comment author, 2: Post title',
'%1$s\'s %3$s on %2$s deleted permanently',
'1: Comment author, 2: Post title, 3: Comment type',
'stream'
),
compact( 'user_name', 'post_title', 'post_id', 'user_id' ),
compact( 'user_name', 'post_title', 'comment_type', 'post_id', 'user_id' ),
$comment_id,
array( $post_type => 'deleted' )
);
Expand All @@ -292,19 +331,20 @@ public static function callback_trash_comment( $comment_id ) {
return;
}

$user_id = self::get_comment_author( $comment, 'id' );
$user_name = self::get_comment_author( $comment, 'name' );
$post_id = $comment->comment_post_ID;
$post_type = get_post_type( $post_id );
$post_title = ( $post = get_post( $post_id ) ) ? "\"$post->post_title\"" : __( 'a post', 'stream' );
$user_id = self::get_comment_author( $comment, 'id' );
$user_name = self::get_comment_author( $comment, 'name' );
$post_id = $comment->comment_post_ID;
$post_type = get_post_type( $post_id );
$post_title = ( $post = get_post( $post_id ) ) ? "\"$post->post_title\"" : __( 'a post', 'stream' );
$comment_type = mb_strtolower( self::get_comment_type_label( $comment_id ) );

self::log(
_x(
'%1$s\'s comment on %2$s trashed',
'1: Comment author, 2: Post title',
'%1$s\'s %3$s on %2$s trashed',
'1: Comment author, 2: Post title, 3: Comment type',
'stream'
),
compact( 'user_name', 'post_title', 'post_id', 'user_id' ),
compact( 'user_name', 'post_title', 'comment_type', 'post_id', 'user_id' ),
$comment_id,
array( $post_type => 'trashed' )
);
Expand All @@ -322,19 +362,20 @@ public static function callback_untrash_comment( $comment_id ) {
return;
}

$user_id = self::get_comment_author( $comment, 'id' );
$user_name = self::get_comment_author( $comment, 'name' );
$post_id = $comment->comment_post_ID;
$post_type = get_post_type( $post_id );
$post_title = ( $post = get_post( $post_id ) ) ? "\"$post->post_title\"" : __( 'a post', 'stream' );
$user_id = self::get_comment_author( $comment, 'id' );
$user_name = self::get_comment_author( $comment, 'name' );
$post_id = $comment->comment_post_ID;
$post_type = get_post_type( $post_id );
$post_title = ( $post = get_post( $post_id ) ) ? "\"$post->post_title\"" : __( 'a post', 'stream' );
$comment_type = mb_strtolower( self::get_comment_type_label( $comment_id ) );

self::log(
_x(
'%1$s\'s comment on %2$s restored',
'1: Comment author, 2: Post title',
'%1$s\'s %3$s on %2$s restored',
'1: Comment author, 2: Post title, 3: Comment type',
'stream'
),
compact( 'user_name', 'post_title', 'post_id', 'user_id' ),
compact( 'user_name', 'post_title', 'comment_type', 'post_id', 'user_id' ),
$comment_id,
array( $post_type => 'untrashed' )
);
Expand All @@ -352,19 +393,20 @@ public static function callback_spam_comment( $comment_id ) {
return;
}

$user_id = self::get_comment_author( $comment, 'id' );
$user_name = self::get_comment_author( $comment, 'name' );
$post_id = $comment->comment_post_ID;
$post_type = get_post_type( $post_id );
$post_title = ( $post = get_post( $post_id ) ) ? "\"$post->post_title\"" : __( 'a post', 'stream' );
$user_id = self::get_comment_author( $comment, 'id' );
$user_name = self::get_comment_author( $comment, 'name' );
$post_id = $comment->comment_post_ID;
$post_type = get_post_type( $post_id );
$post_title = ( $post = get_post( $post_id ) ) ? "\"$post->post_title\"" : __( 'a post', 'stream' );
$comment_type = mb_strtolower( self::get_comment_type_label( $comment_id ) );

self::log(
_x(
'%1$s\'s comment on %2$s marked as spam',
'1: Comment author, 2: Post title',
'%1$s\'s %3$s on %2$s marked as spam',
'1: Comment author, 2: Post title, 3: Comment type',
'stream'
),
compact( 'user_name', 'post_title', 'post_id', 'user_id' ),
compact( 'user_name', 'post_title', 'comment_type', 'post_id', 'user_id' ),
$comment_id,
array( $post_type => 'spammed' )
);
Expand All @@ -382,19 +424,20 @@ public static function callback_unspam_comment( $comment_id ) {
return;
}

$user_id = self::get_comment_author( $comment, 'id' );
$user_name = self::get_comment_author( $comment, 'name' );
$post_id = $comment->comment_post_ID;
$post_type = get_post_type( $post_id );
$post_title = ( $post = get_post( $post_id ) ) ? "\"$post->post_title\"" : __( 'a post', 'stream' );
$user_id = self::get_comment_author( $comment, 'id' );
$user_name = self::get_comment_author( $comment, 'name' );
$post_id = $comment->comment_post_ID;
$post_type = get_post_type( $post_id );
$post_title = ( $post = get_post( $post_id ) ) ? "\"$post->post_title\"" : __( 'a post', 'stream' );
$comment_type = mb_strtolower( self::get_comment_type_label( $comment_id ) );

self::log(
_x(
'%1$s\'s comment on %2$s unmarked as spam',
'1: Comment author, 2: Post title',
'%1$s\'s %3$s on %2$s unmarked as spam',
'1: Comment author, 2: Post title, 3: Comment type',
'stream'
),
compact( 'user_name', 'post_title', 'post_id', 'user_id' ),
compact( 'user_name', 'post_title', 'comment_type', 'post_id', 'user_id' ),
$comment_id,
array( $post_type => 'unspammed' )
);
Expand All @@ -414,19 +457,20 @@ public static function callback_transition_comment_status( $new_status, $old_sta
return;
}

$user_id = self::get_comment_author( $comment, 'id' );
$user_name = self::get_comment_author( $comment, 'name' );
$post_id = $comment->comment_post_ID;
$post_type = get_post_type( $post_id );
$post_title = ( $post = get_post( $post_id ) ) ? "\"$post->post_title\"" : __( 'a post', 'stream' );
$user_id = self::get_comment_author( $comment, 'id' );
$user_name = self::get_comment_author( $comment, 'name' );
$post_id = $comment->comment_post_ID;
$post_type = get_post_type( $post_id );
$post_title = ( $post = get_post( $post_id ) ) ? "\"$post->post_title\"" : __( 'a post', 'stream' );
$comment_type = get_comment_type( $comment->comment_ID );

self::log(
_x(
'%1$s\'s comment %2$s',
'Comment status transition. 1: Comment author, 2: Post title',
'%1$s\'s %3$s %2$s',
'Comment status transition. 1: Comment author, 2: Post title, 3: Comment type',
'stream'
),
compact( 'user_name', 'new_status', 'old_status', 'post_title', 'post_id', 'user_id' ),
compact( 'user_name', 'new_status', 'comment_type', 'old_status', 'post_title', 'post_id', 'user_id' ),
$comment->comment_ID,
array( $post_type => $new_status )
);
Expand All @@ -447,19 +491,20 @@ public static function callback_comment_duplicate_trigger( $comment_data ) {
return;
}

$user_id = self::get_comment_author( $comment, 'id' );
$user_name = self::get_comment_author( $comment, 'name' );
$post_id = $comment->comment_post_ID;
$post_type = get_post_type( $post_id );
$post_title = ( $post = get_post( $post_id ) ) ? "\"$post->post_title\"" : __( 'a post', 'stream' );
$user_id = self::get_comment_author( $comment, 'id' );
$user_name = self::get_comment_author( $comment, 'name' );
$post_id = $comment->comment_post_ID;
$post_type = get_post_type( $post_id );
$post_title = ( $post = get_post( $post_id ) ) ? "\"$post->post_title\"" : __( 'a post', 'stream' );
$comment_type = mb_strtolower( self::get_comment_type_label( $comment_id ) );

self::log(
_x(
'Duplicate comment by %1$s prevented on %2$s',
'1: Comment author, 2: Post title',
'Duplicate %3$s by %1$s prevented on %2$s',
'1: Comment author, 2: Post title, 3: Comment type',
'stream'
),
compact( 'user_name', 'post_title', 'post_id', 'user_id' ),
compact( 'user_name', 'post_title', 'comment_type', 'post_id', 'user_id' ),
$comment_id,
array( $post_type => 'duplicate' )
);
Expand Down