Skip to content

ImageData support captions #35

Description

@WybeBosch

Ik zag dat de meest gebruikte opties al wel supported waren
namelijk alt en url, maar toevallig moest ik een cover neerzetten en die maken wel vaker gebruik van Captions.
En gezien Caption een wordpress native invoer veld in de mediatheek is, misschien ook goed om daarvoor support te bieden.

Image

File in kwestie:
https://github.com/yardinternet/odmh/blob/feat/further-implementation-initial-design/vendor/yard/data/src/ImageData.php

<?php

declare(strict_types=1);

namespace Yard\Data;

use Spatie\LaravelData\Attributes\MapInputName;
use Spatie\LaravelData\Data;

class ImageData extends Data
{
    public function __construct(
        #[MapInputName('meta_value')]
        public int|string $id,
    ) {
    }

    public function alt(string $default = ''): string
    {
        $alt = get_post_meta((int) $this->id, '_wp_attachment_image_alt', true);

        return is_string($alt) && '' !== $alt ? $alt : $default;
    }

    public function url(string $size = 'medium_large'): string
    {
        return wp_get_attachment_image_url((int) $this->id, $size) ?: '';
    }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions