PluginProbe ʕ •ᴥ•ʔ
Kirki – Freeform Page Builder, Website Builder & Customizer / 6.0.13
Kirki – Freeform Page Builder, Website Builder & Customizer v6.0.13
6.1.1 6.1.0 6.0.14 6.0.13 6.0.12 6.0.11 6.0.10 6.0.9 6.0.8 6.0.7 6.0.6 6.0.5 6.0.4 6.0.3 6.0.2 6.0.1 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 4.0.19 4.0.20 4.0.21 4.0.22 4.0.23 4.0.24 4.1 4.2.0 5.0.0 5.1.0 5.1.1 5.2.0 5.2.1 5.2.2 5.2.3 6.0.0 trunk 3.0.40 3.0.41 3.0.42 3.0.43 3.0.44 3.0.45 3.1.0 3.1.1 3.1.2
kirki / app / Resources / Media / MediaResource.php
kirki / app / Resources / Media Last commit date
MediaResource.php 3 weeks ago
MediaResource.php
69 lines
1 <?php
2
3 namespace Kirki\App\Resources\Media;
4
5 use Kirki\App\Constants\PostStatus;
6 use function Kirki\Framework\config;
7
8 defined('ABSPATH') || exit;
9
10 use Kirki\Framework\Resource;
11
12 class MediaResource extends Resource
13 {
14 /**
15 * Convert the media resource to an array.
16 *
17 * @return array The media data as an associative array.
18 */
19 public function to_array()
20 {
21 $categories = config('media.supports', []);
22 $category = '';
23
24 foreach ($categories as $type => $mime_types) {
25 if (in_array($this->post_mime_type, $mime_types, true)) {
26 $category = $type === 'svg' ? 'image' : $type;
27 break;
28 }
29 }
30
31 $meta = $this->mapped_meta();
32
33 $alt = $meta['_wp_attachment_image_alt'] ?? '';
34 $file_path = $meta['_wp_attached_file'] ?? '';
35 $file_meta = $meta['_wp_attachment_metadata'] ?? '';
36 $file_size = $file_meta['filesize'] ?? 0;
37 $file_extension = $file_path ? pathinfo($file_path, PATHINFO_EXTENSION) : '';
38
39 return [
40 'id' => (int) $this->ID,
41 'name' => $this->post_name,
42 'alt' => $alt ? $alt : $this->post_title,
43 'type' => $this->post_mime_type,
44 'url' => $this->guid,
45 'thumbnail' => wp_get_attachment_image_url($this->ID),
46 'category' => $category,
47 'trash' => PostStatus::TRASH === $this->post_status,
48 'file_size' => size_format($file_size),
49 'file_extension' => $file_extension,
50 ];
51 }
52
53 /**
54 * Map the item's meta as meta_key => meta_value.
55 *
56 * @return array<string, mixed>
57 */
58 protected function mapped_meta()
59 {
60 $map = [];
61
62 foreach ($this->meta ?? [] as $meta) {
63 $map[$meta->meta_key] = $meta->meta_value;
64 }
65
66 return $map;
67 }
68 }
69