Skip to content

Commit

Permalink
Merge pull request #488 from x-team/issue-487
Browse files Browse the repository at this point in the history
Issue 487: Add ignored comment types to comments connector
  • Loading branch information
frankiejarrett committed May 9, 2014
2 parents 650df12 + b0c9c69 commit 61f7d59
Showing 1 changed file with 61 additions and 6 deletions.
67 changes: 61 additions & 6 deletions connectors/comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ public static function callback_comment_flood_trigger( $time_lastcomment, $time_
* @action wp_insert_comment
*/
public static function callback_wp_insert_comment( $comment_id, $comment ) {
if ( in_array( $comment->comment_type, self::get_ignored_comment_types() ) ) {
return;
}

$user_id = self::get_comment_author( $comment, 'id' );
$user_name = self::get_comment_author( $comment, 'name' );
$post_id = $comment->comment_post_ID;
Expand Down Expand Up @@ -222,7 +226,12 @@ public static function callback_wp_insert_comment( $comment_id, $comment ) {
* @action edit_comment
*/
public static function callback_edit_comment( $comment_id ) {
$comment = get_comment( $comment_id );
$comment = get_comment( $comment_id );

if ( in_array( $comment->comment_type, self::get_ignored_comment_types() ) ) {
return;
}

$user_id = self::get_comment_author( $comment, 'id' );
$user_name = self::get_comment_author( $comment, 'name' );
$post_id = $comment->comment_post_ID;
Expand All @@ -247,7 +256,12 @@ public static function callback_edit_comment( $comment_id ) {
* @action delete_comment
*/
public static function callback_delete_comment( $comment_id ) {
$comment = get_comment( $comment_id );
$comment = get_comment( $comment_id );

if ( in_array( $comment->comment_type, self::get_ignored_comment_types() ) ) {
return;
}

$user_id = self::get_comment_author( $comment, 'id' );
$user_name = self::get_comment_author( $comment, 'name' );
$post_id = $comment->comment_post_ID;
Expand All @@ -272,7 +286,12 @@ public static function callback_delete_comment( $comment_id ) {
* @action trash_comment
*/
public static function callback_trash_comment( $comment_id ) {
$comment = get_comment( $comment_id );
$comment = get_comment( $comment_id );

if ( in_array( $comment->comment_type, self::get_ignored_comment_types() ) ) {
return;
}

$user_id = self::get_comment_author( $comment, 'id' );
$user_name = self::get_comment_author( $comment, 'name' );
$post_id = $comment->comment_post_ID;
Expand All @@ -297,7 +316,12 @@ public static function callback_trash_comment( $comment_id ) {
* @action untrash_comment
*/
public static function callback_untrash_comment( $comment_id ) {
$comment = get_comment( $comment_id );
$comment = get_comment( $comment_id );

if ( in_array( $comment->comment_type, self::get_ignored_comment_types() ) ) {
return;
}

$user_id = self::get_comment_author( $comment, 'id' );
$user_name = self::get_comment_author( $comment, 'name' );
$post_id = $comment->comment_post_ID;
Expand All @@ -322,7 +346,12 @@ public static function callback_untrash_comment( $comment_id ) {
* @action spam_comment
*/
public static function callback_spam_comment( $comment_id ) {
$comment = get_comment( $comment_id );
$comment = get_comment( $comment_id );

if ( in_array( $comment->comment_type, self::get_ignored_comment_types() ) ) {
return;
}

$user_id = self::get_comment_author( $comment, 'id' );
$user_name = self::get_comment_author( $comment, 'name' );
$post_id = $comment->comment_post_ID;
Expand All @@ -347,7 +376,12 @@ public static function callback_spam_comment( $comment_id ) {
* @action unspam_comment
*/
public static function callback_unspam_comment( $comment_id ) {
$comment = get_comment( $comment_id );
$comment = get_comment( $comment_id );

if ( in_array( $comment->comment_type, self::get_ignored_comment_types() ) ) {
return;
}

$user_id = self::get_comment_author( $comment, 'id' );
$user_name = self::get_comment_author( $comment, 'name' );
$post_id = $comment->comment_post_ID;
Expand All @@ -372,6 +406,10 @@ public static function callback_unspam_comment( $comment_id ) {
* @action transition_comment_status
*/
public static function callback_transition_comment_status( $new_status, $old_status, $comment ) {
if ( in_array( $comment->comment_type, self::get_ignored_comment_types() ) ) {
return;
}

if ( 'approved' !== $new_status && 'unapproved' !== $new_status || 'trash' === $old_status || 'spam' === $old_status ) {
return;
}
Expand Down Expand Up @@ -404,6 +442,11 @@ public static function callback_comment_duplicate_trigger( $comment_data ) {

$comment_id = $wpdb->last_result[0]->comment_ID;
$comment = get_comment( $comment_id );

if ( in_array( $comment->comment_type, self::get_ignored_comment_types() ) ) {
return;
}

$user_id = self::get_comment_author( $comment, 'id' );
$user_name = self::get_comment_author( $comment, 'name' );
$post_id = $comment->comment_post_ID;
Expand All @@ -422,4 +465,16 @@ public static function callback_comment_duplicate_trigger( $comment_data ) {
);
}

/**
* Constructs list of ignored comment types for the comments connector
*
* @return array List of ignored comment types
*/
public static function get_ignored_comment_types() {
return apply_filters(
'wp_stream_comment_exclude_comment_types',
array()
);
}

}

0 comments on commit 61f7d59

Please sign in to comment.