/** * Remove order notes from wp_count_comments() * * */ public function filter_count_comments($stats, $post_id) { global $wpdb; if (0 === $post_id) { $count = wp_cache_get('comments-mpp', 'counts'); if (false !== $count) { return $count; } $count = $wpdb->get_results($wpdb->prepare("SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} WHERE comment_type != %s GROUP BY comment_approved", mpp_get_comment_type()), ARRAY_A); $total = 0; $approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam', 'trash' => 'trash', 'post-trashed' => 'post-trashed'); foreach ((array) $count as $row) { // Don't count post-trashed toward totals if ('post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved']) { $total += $row['num_comments']; } if (isset($approved[$row['comment_approved']])) { $stats[$approved[$row['comment_approved']]] = $row['num_comments']; } } $stats['total_comments'] = $total; foreach ($approved as $key) { if (empty($stats[$key])) { $stats[$key] = 0; } } $stats = (object) $stats; wp_cache_set('comments-mpp', $stats, 'counts'); } return $stats; }
private function __construct() { $this->comment_type = mpp_get_comment_type(); // Hide in comment listing add_filter('comments_clauses', array($this, 'exclude_comments'), 10, 2); add_filter('comment_feed_where', array($this, 'exclude_from_feeds'), 10, 2); // Update count comments add_filter('wp_count_comments', array($this, 'filter_count_comments'), 10, 2); }
/** * On New Activity Comment, Create a new shadow WordPress comment too * * @param type $comment_id * @param type $param * @param type $activity * @return type */ function mpp_activity_synchronize_reply_to_comment($comment_id, $param, $activity) { //it must be upload from activity //so lt us crea //check that the media was posted in activity $gallery_id = mpp_activity_get_gallery_id($activity->id); if (!$gallery_id) { return; } $bp_comment = new BP_Activity_Activity($comment_id); //now we need to add a comment // //my logic to find the parent may be flawed here, Needs a confirmation from other people if ($bp_comment->secondary_item_id != $activity->id) { $parent_id = $bp_comment->secondary_item_id; //this is a multilevel comment //we will add a child comment in wp too as the } else { $parent_id = $activity->id; } $wp_comment_parent_id = (int) mpp_activity_get_associated_comment_id($parent_id); //if we are here, It must be an activity where we have uploaded media //we will create a comment and add if ($wp_comment_parent_id > 0) { //we have a parent comment associated, so we will be adding a child comment $wp_comment = get_comment($wp_comment_parent_id); } $commetn_data = array('post_id' => $gallery_id, 'user_id' => get_current_user_id(), 'comment_parent' => $wp_comment_parent_id, 'comment_content' => $bp_comment->content, 'comment_type' => mpp_get_comment_type()); $new_comment_id = mpp_add_comment($commetn_data); //update comment meta if ($new_comment_id) { mpp_update_comment_meta($new_comment_id, '_mpp_activity_id', $comment_id); mpp_activity_update_associated_comment_id($comment_id, $new_comment_id); } }
function mpp_activity_create_comment_for_activity($activity_id) { if (!$activity_id || !mpp_get_option('activity_comment_sync')) { return; } $activity = new BP_Activity_Activity($activity_id); if ($activity->type != 'mpp_media_upload') { return; } $gallery_id = mpp_activity_get_gallery_id($activity_id); $media_id = mpp_activity_get_media_id($activity_id); //this is not MediaPress activity if (!$gallery_id && !$media_id) { return; } //parent post id for the comment $parent_id = $media_id > 0 ? $media_id : $gallery_id; //now, create a top level comment and save $comment_data = array('post_id' => $parent_id, 'user_id' => get_current_user_id(), 'comment_parent' => 0, 'comment_content' => $activity->content, 'comment_type' => mpp_get_comment_type()); $comment_id = mpp_add_comment($comment_data); //update comment meta if ($comment_id) { mpp_update_comment_meta($comment_id, '_mpp_activity_id', $activity_id); mpp_activity_update_associated_comment_id($activity_id, $comment_id); //also since there are media attched and we are mirroring activity, let us save the attached media too $media_ids = mpp_activity_get_attached_media_ids($activity_id); //it is a gallery upload post from activity if ($gallery_id && !empty($media_ids)) { //only available when sync is enabled if (function_exists('mpp_comment_update_attached_media_ids')) { mpp_comment_update_attached_media_ids($comment_id, $media_ids); } } //most probably a comment on media if (!empty($media_id)) { //should we add media as the comment meta? no, we don't need that at the moment } } }