fix: add missing methods to includes/Tools/MediaTools.php

This commit is contained in:
2026-05-29 12:20:31 +00:00
parent 2c674a4b8d
commit d5708a0aa3
+14
View File
@@ -68,4 +68,18 @@ class MediaTools {
if (!$result) throw new \RuntimeException("Failed to delete media: {$args['media_id']}"); if (!$result) throw new \RuntimeException("Failed to delete media: {$args['media_id']}");
return ['id' => (int) $args['media_id'], 'deleted' => true]; return ['id' => (int) $args['media_id'], 'deleted' => true];
} }
public static function countMedia(array $args): array {
global $wpdb;
$rows = $wpdb->get_results("SELECT post_mime_type, COUNT(*) as cnt FROM {$wpdb->posts} WHERE post_type='attachment' AND post_status='inherit' GROUP BY post_mime_type", ARRAY_A);
$counts = ['total'=>0,'image'=>0,'video'=>0,'audio'=>0,'document'=>0,'other'=>0];
foreach ($rows as $r) {
$counts['total'] += (int)$r['cnt'];
$type = explode('/',$r['post_mime_type'])[0];
if (isset($counts[$type])) $counts[$type] += (int)$r['cnt'];
else $counts['other'] += (int)$r['cnt'];
}
return $counts;
}
} }