Audio
4 days ago
Video
4 days ago
AttachmentMetaData.php
4 days ago
AttachmentUrl.php
4 days ago
AudioPlayer.php
4 days ago
AvailableSizes.php
4 days ago
Dimensions.php
4 days ago
Download.php
4 days ago
ExifData.php
4 days ago
FileLinkToUrl.php
4 days ago
FileName.php
4 days ago
FileSize.php
4 days ago
Link.php
4 days ago
NestedAttachmentMetaData.php
4 days ago
NumberFormat.php
4 days ago
PostMimeType.php
4 days ago
PreviewViewLink.php
4 days ago
VideoEmbed.php
4 days ago
AttachmentUrl.php
29 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\Type\Value; |
| 10 | |
| 11 | class AttachmentUrl implements Formatter |
| 12 | { |
| 13 | public function format(Value $value): Value |
| 14 | { |
| 15 | if (! $value->get_id()) { |
| 16 | return $value; |
| 17 | } |
| 18 | |
| 19 | $url = wp_get_attachment_url($value->get_id()); |
| 20 | |
| 21 | if (! $url) { |
| 22 | throw ValueNotFoundException::from_id($value->get_id()); |
| 23 | } |
| 24 | |
| 25 | return $value->with_value($url); |
| 26 | } |
| 27 | |
| 28 | } |
| 29 |