public function count_attachments($prefix, $uploaded_to_s3 = null)
{
global $wpdb;
$sql = "SELECT COUNT(*)\n\t\t\t\tFROM `{$prefix}posts` p";
$where = "WHERE p.post_type = 'attachment'";
if (!is_null($uploaded_to_s3) && is_bool($uploaded_to_s3)) {
$sql .= " LEFT OUTER JOIN `{$prefix}postmeta` pm\n\t\t\t\t\tON p.`ID` = pm.`post_id`\n\t\t\t\t\tAND pm.`meta_key` = 'amazonS3_info'";
$operator = $uploaded_to_s3 ? 'not ' : '';
$where .= " AND pm.`post_id` is {$operator}null";
}
$sql .= ' ' . $where;
return (int) $wpdb->get_var($sql);
}