Amazon_S3_And_CloudFront::count_attachments PHP Method

count_attachments() public method

Count attachments on a site
public count_attachments ( string $prefix, null | boolean $uploaded_to_s3 = null ) : integer
$prefix string
$uploaded_to_s3 null | boolean null - All attachments true - Attachments only uploaded to S3 false - Attachments not uploaded to S3
return integer
    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);
    }
Amazon_S3_And_CloudFront