Finds the most recent comments that are available to the current user.
integer $number: (optional) The maximum number of comments to find. Defaults to 10.
An array of comment objects or an empty array if there are no recent comments visible to the current user.
function comment_get_recent($number = 10) {
$query = db_select('comment', 'c');
$query
->innerJoin('node_field_data', 'n', 'n.nid = c.nid');
$query
->addTag('node_access');
$query
->addMetaData('base_table', 'comment');
$comments = $query
->fields('c')
->condition('c.status', COMMENT_PUBLISHED)
->condition('n.status', NODE_PUBLISHED)
->condition('n.default_langcode', 1)
->orderBy('c.created', 'DESC')
->orderBy('c.cid', 'DESC')
->range(0, $number)
->execute()
->fetchAll();
return $comments ? $comments : array();
}