/** * When a blog comment status transition occurs, update the relevant activity's status. * * @global object $bp BuddyPress global settings * @param string $new_status New comment status. * @param string $old_status Previous comment status. * @param object $comment Comment data. * @since 1.6 */ function bp_blogs_transition_activity_status($new_status, $old_status, $comment) { global $bp; // Check the Activity component is active if (!bp_is_active('activity')) { return; } /** * Activity currently doesn't have any concept of a trash, or an unapproved/approved state. * * If a blog comment transitions to a "delete" or "hold" status, delete the activity item. * If a blog comment transitions to trashed, or spammed, mark the activity as spam. * If a blog comment transitions to approved (and the activity exists), mark the activity as ham. * Otherwise, record the comment into the activity stream. */ // This clause was moved in from bp_blogs_remove_comment() in BuddyPress 1.6. It handles delete/hold. if (in_array($new_status, array('delete', 'hold'))) { return bp_blogs_remove_comment($comment->comment_ID); } elseif (in_array($new_status, array('trash', 'spam'))) { $action = 'spam_activity'; } elseif ('approved' == $new_status) { $action = 'ham_activity'; } // Get the activity $activity_id = bp_activity_get_activity_id(array('component' => $bp->blogs->id, 'item_id' => get_current_blog_id(), 'secondary_item_id' => $comment->comment_ID, 'type' => 'new_blog_comment')); // Check activity item exists if (!$activity_id) { // If no activity exists, but the comment has been approved, record it into the activity table. if ('approved' == $new_status) { return bp_blogs_record_comment($comment->comment_ID, true); } return; } // Create an activity object $activity = new BP_Activity_Activity($activity_id); if (empty($activity->component)) { return; } // Spam/ham the activity if it's not already in that state if ('spam_activity' == $action && !$activity->is_spam) { bp_activity_mark_as_spam($activity); } elseif ('ham_activity' == $action) { bp_activity_mark_as_ham($activity); } // Add "new_blog_comment" to the whitelisted activity types, so that the activity's Akismet history is generated $comment_akismet_history = create_function('$t', '$t[] = "new_blog_comment"; return $t;'); add_filter('bp_akismet_get_activity_types', $comment_akismet_history); // Save the updated activity $activity->save(); // Remove the "new_blog_comment" activity type whitelist so we don't break anything remove_filter('bp_akismet_get_activity_types', $comment_akismet_history); }
/** * Manage activities about idea comments * * @package WP Idea Stream * @subpackage buddypress/activity * * @since 2.0.0 * * @param string $new_status comment status applyed * @param string $old_status previous comment status * @param object $comment the comment object * @uses get_post_type() to get the post post type * @uses remove_action() to remove BuddyPress actions * @uses bp_activity_get() to get activities * @uses bp_activity_delete() to delete activities */ public function manage_comment_activity($new_status = '', $old_status = '', $comment = null) { // Bail if no post id, as we need to check for the post type if (empty($comment->comment_post_ID)) { return; } // Not a comment about an idea ? Bail. if ($this->post_type != get_post_type($comment->comment_post_ID)) { return; } // Avoid BuddyPress to manage transtion status, we'll manage idea comments ourselves remove_action('transition_comment_status', 'bp_blogs_transition_activity_status'); /** * If the new status is approved, and we already created the activity bail, it should be * the case if comment was edited from wp-admin/comment.php?action=editcomment screen */ if ('approved' == $new_status && !empty($this->secondary_item_id) && $this->secondary_item_id == $comment->comment_ID) { return; } $activity_comments = bp_activity_get(array('filter' => array('action' => 'new_' . $this->post_type . '_comment', 'secondary_id' => $comment->comment_ID), 'show_hidden' => true, 'spam' => 'all', 'per_page' => false)); // No activities and status is approved. if (empty($activity_comments['activities']) && 'approved' == $new_status) { // Record an activity bp_blogs_record_comment($comment->comment_ID, true); /** * Else status should be 'delete', 'hold', 'trash', 'spam', 'unapproved' * For all these cases, simply remove the activity. */ } else { if (!empty($activity_comments['activities']) && 'approved' != $new_status) { // Safely delete activities having status != approved foreach ((array) $activity_comments['activities'] as $activity) { bp_activity_delete(array('id' => $activity->id)); } } } }
function bp_blogs_manage_comment($comment_id, $comment_status) { if ('spam' == $comment_status || 'hold' == $comment_status || 'delete' == $comment_status || 'trash' == $comment_status) { return bp_blogs_remove_comment($comment_id); } return bp_blogs_record_comment($comment_id, true); }
function bp_blogs_approve_comment($comment_id, $comment) { global $bp, $wpdb; $recorded_comment = bp_blogs_record_comment($comment_id, true); bp_blogs_delete_activity(array('item_id' => $recorded_comment->blog_id, 'secondary_item_id' => $recorded_commment_id, 'component_name' => 'blogs', 'component_action' => 'new_blog_comment', 'user_id' => $recorded_comment->user_id)); bp_blogs_record_activity(array('item_id' => $recorded_comment->blog_id, 'secondary_item_id' => $recorded_commment_id, 'component_name' => 'blogs', 'component_action' => 'new_blog_comment', 'is_private' => $is_private, 'user_id' => $recorded_comment->user_id, 'recorded_time' => $recorded_comment->date_created)); }