private function get_attachment_paths()
{
$metadata = $this->db->get_results("SELECT meta_value FROM {$this->db->postmeta} WHERE meta_key = '_wp_attachment_metadata'");
if (!$metadata) {
return [];
}
$attachment_paths = array_reduce($metadata, function (array $attachment_paths, $metadata) {
$meta_value = maybe_unserialize($metadata->meta_value);
if (empty($meta_value['file'])) {
return $attachment_paths;
}
$file = $meta_value['file'];
$dir = dirname($file);
$attachment_paths[$dir][] = basename($file);
if (empty($meta_value['sizes'])) {
return $attachment_paths;
}
$sizes = $meta_value['sizes'];
$attachment_paths[$dir] = array_reduce($sizes, function (array $dirs, array $size) {
$dirs[] = $size['file'];
return $dirs;
}, $attachment_paths[$dir]);
return $attachment_paths;
}, []);
return $attachment_paths;
}