PluginProbe ʕ •ᴥ•ʔ
Admin Columns / 7.0.13
Admin Columns v7.0.13
7.1.4 7.0.19 2.3.5 2.4 2.4.1 2.4.10 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.6.1 2.5.6.2 2.5.6.3 2.5.6.4 3.0 3.0.1 3.0.2 3.0.3 3.0.5 3.0.7 3.1 3.1.1 3.1.10 3.1.2 3.1.3 3.1.5 3.2.3 3.2.7 3.3.1 3.4.1 3.4.6 3.4.8 4.0.1 4.0.3 4.1.6 4.2.2 4.2.5 4.3 4.3.2 4.4.1 4.4.4 4.4.5 4.5.5 4.6.1 4.7.18 4.7.19 4.7.20 4.7.7 7.0.13 7.0.14 7.0.16 trunk 1.0 1.1 1.1.3 1.2 1.2.1 1.3 1.3.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.5.1 1.4.6 1.4.6.1 1.4.6.2 1.4.6.3 1.4.6.4 1.4.7 1.4.8 1.4.9 2.0.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.2 2.2.1 2.2.1.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.5.1 2.2.6 2.2.6.1 2.2.6.2 2.2.6.3 2.2.6.4 2.2.7 2.2.8 2.2.8.1 2.2.9 2.3.1 2.3.2 2.3.3
codepress-admin-columns / classes / Formatter / Media / AvailableSizes.php
codepress-admin-columns / classes / Formatter / Media Last commit date
Audio 5 months ago Video 5 months ago AttachmentMetaData.php 5 months ago AttachmentUrl.php 5 months ago AudioPlayer.php 5 months ago AvailableSizes.php 5 months ago Dimensions.php 5 months ago Download.php 5 months ago ExifData.php 5 months ago FileLinkToUrl.php 5 months ago FileName.php 5 months ago FileSize.php 5 months ago Link.php 5 months ago NestedAttachmentMetaData.php 5 months ago NumberFormat.php 5 months ago PostMimeType.php 5 months ago PreviewViewLink.php 5 months ago VideoEmbed.php 5 months ago
AvailableSizes.php
96 lines
1 <?php
2
3 declare(strict_types=1);
4
5 namespace AC\Formatter\Media;
6
7 use AC\Exception\ValueNotFoundException;
8 use AC\Formatter;
9 use AC\Helper;
10 use AC\Type\Value;
11
12 class AvailableSizes implements Formatter
13 {
14
15 private bool $include_missing_file_sizes;
16
17 public function __construct(bool $include_missing_file_sizes)
18 {
19 $this->include_missing_file_sizes = $include_missing_file_sizes;
20 }
21
22 public function format(Value $value): Value
23 {
24 $meta = get_post_meta($value->get_id(), '_wp_attachment_metadata', true);
25 $sizes = $meta['sizes'] ?? null;
26
27 if ( ! $sizes) {
28 throw new ValueNotFoundException();
29 }
30
31 $paths = [];
32
33 $available_sizes = $this->get_available_sizes($sizes);
34
35 if ($available_sizes) {
36 $url = wp_get_attachment_url($value->get_id());
37 $paths[] = Helper\Html::create()->tooltip(
38 Helper\Html::create()->link($url, __('original', 'codepress-admin-columns')),
39 basename($url)
40 );
41
42 foreach ($available_sizes as $size) {
43 $src = (array)wp_get_attachment_image_src($value->get_id(), $size);
44
45 if ( ! empty($src[0])) {
46 $paths[] = Helper\Html::create()->tooltip(Helper\Html::create()->link($src[0], $size), basename($src[0]));
47 }
48 }
49 }
50
51 if ($this->include_missing_file_sizes) {
52 $missing = $this->get_missing_sizes($sizes);
53
54 if ($missing) {
55 foreach ($missing as $size) {
56 $paths[] = Helper\Html::create()->tooltip(
57 $size,
58 sprintf(
59 __('Missing image file for size %s.', 'codepress-admin-columns'),
60 '<em>"' . $size . '"</em>'
61 ),
62 ['class' => 'ac-missing-size']
63 );
64 }
65 }
66 }
67
68 return $value->with_value(
69 "<div class='ac-image-sizes'>" . implode(Helper\Html::create()->divider(), $paths) . "</div>"
70 );
71 }
72
73 private function get_available_sizes(array $image_sizes): array
74 {
75 return array_intersect(array_keys($image_sizes), get_intermediate_image_sizes());
76 }
77
78 private function get_missing_sizes(array $image_sizes): array
79 {
80 global $_wp_additional_image_sizes;
81
82 if (empty($_wp_additional_image_sizes)) {
83 return [];
84 }
85
86 $additional_size = $_wp_additional_image_sizes;
87
88 if (isset($additional_size['post-thumbnail'])) {
89 unset($additional_size['post-thumbnail']);
90 }
91
92 // image does not have these additional sizes rendered yet
93 return array_diff(array_keys((array)$additional_size), array_keys($image_sizes));
94 }
95
96 }