fix: add missing methods to includes/Tools/MediaTools.php
This commit is contained in:
@@ -68,4 +68,18 @@ class MediaTools {
|
||||
if (!$result) throw new \RuntimeException("Failed to delete media: {$args['media_id']}");
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user