Jake Vanderwerf
2026-05-03 9bbeea742424837fb58207d88e10dbca0b2cae04
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
namespace JVBase\managers\SEO\render\Traits\_Properties;
 
use JVBase\managers\SEO\render\Thing\CreativeWork\MediaObject\ImageObject;
use JVBase\managers\SEO\render\Thing\CreativeWork\Photograph;
use JVBase\meta\Meta;
use JVBase\registrar\Fields;
 
if (!defined('ABSPATH')) {
    exit;
}
trait photoTrait {
    /**
     * @var ImageObject|Photograph A photograph of this place. Supersedes photos.
     */
    protected ImageObject|Photograph $photo;
 
    public function getPhoto():ImageObject|Photograph|null
    {
        return $this->photo??null;
    }
    public function setPhoto(ImageObject|Photograph $photo):void
    {
        $this->photo = $photo;
    }
 
    public function getPhotoFieldConfig():array
    {
        return [
            'type'  => 'upload',
            'multiple'  => false,
            'label' => 'Photo',
            'hint'  => 'A photograph of this place.'
        ];
    }
    public function setPhotoField(Fields $fields):void
    {
        $fields->addField(
            'outside_photo',
            [
                'type'  => 'image',
                'limit' => 1,
                'label' => __('Outside Photo', 'jvb')
            ]
        );
    }
 
    public function formatPhotoField(Meta $meta):void
    {
        $image = $meta->get('outside_photo');
        if (!empty($image) && $image > 0) {
            $image = $this->createImageFromID($image);
            if ($image) {
                $this->setPhoto($image);
            }
        }
    }
}