/** * @group wp_idea_stream_comments_get_comments */ public function test_wp_idea_stream_comments_get_comments() { $comment_id_approved = $this->factory->comment->create(array('comment_post_ID' => $this->idea_id)); $comment_id_not_approved = $this->factory->comment->create(array('comment_post_ID' => $this->idea_id, 'comment_approved' => 0)); $p = $this->factory->post->create(); $comment_id_post = $this->factory->comment->create(array('comment_post_ID' => $p)); $a_comments = wp_idea_stream_comments_get_comments(); $this->assertTrue(1 == count($a_comments)); $this->assertEquals(array($comment_id_approved), wp_list_pluck($a_comments, 'comment_ID')); $h_comments = wp_idea_stream_comments_get_comments(array('status' => 'hold')); $this->assertEquals(array($comment_id_not_approved), wp_list_pluck($h_comments, 'comment_ID')); }
/** * Gets a list of activity ids to manage * * Generally, it's the activity id about an idea merged with the activities * recorded for the comments about this idea. * * @package WP Idea Stream * @subpackage buddypress/activity * * @since 2.0.0 * * @param int $idea_id the idea ID * @param string $post_status the status of the idea * @param string $post_password the post password if set * @uses bp_activity_get() to get activities * @uses wp_idea_stream_get_post_type() to get the idea post type * @uses wp_idea_stream_comments_get_comments() to get the comments about the idea * @uses wp_filter_object_list() filters a list of objects, based on a set of key => value arguments. * @uses wp_list_pluck() to pluck a certain field out of each object in a list. * @return array activity ids to manage */ public function get_idea_and_comments($idea_id = 0, $post_status = 'publish', $post_password = '') { $idea_and_comments = array(); if (empty($idea_id)) { return $idea_and_comments; } // We have a matching catched value, return it if (!empty($this->edit_activities[$idea_id])) { return $this->edit_activities[$idea_id]; } // try to get the activity about the idea $activity = bp_activity_get(array('filter' => array('action' => 'new_' . wp_idea_stream_get_post_type(), 'secondary_id' => $idea_id), 'show_hidden' => true, 'spam' => 'all', 'per_page' => false)); // Case when the activity is deleted but we need to get the comments $already_deleted = (bool) (!empty($post_password)) || in_array($post_status, array('trash', 'draft', 'pending')); // If it exists, add it to the array if (!empty($activity['activities']) || empty($activity['activities']) && $already_deleted) { $idea_and_comments = (array) $activity['activities']; // Check for comments $comments = wp_idea_stream_comments_get_comments(array('fields' => 'ids', 'post_id' => $idea_id, 'post_status' => $post_status)); if (!empty($comments)) { // Do we have activities about the corresponding comments ? $activity_comments = bp_activity_get(array('filter' => array('action' => 'new_' . wp_idea_stream_get_post_type() . '_comment', 'secondary_id' => $comments), 'show_hidden' => true, 'spam' => 'all', 'per_page' => false)); // If found, add comments to the array if (!empty($activity_comments['activities'])) { $idea_and_comments = array_merge($idea_and_comments, (array) $activity_comments['activities']); } } // Do we have privates ? $this->private_activities[$idea_id] = wp_filter_object_list($idea_and_comments, array('hide_sitewide' => 1), 'and', 'id'); // keep only ids $idea_and_comments = wp_list_pluck($idea_and_comments, 'id'); // Catch results $this->edit_activities[$idea_id] = $idea_and_comments; } // Finally return the list of activity ids. return $idea_and_comments; }