acf = $acf;
$this->fieldMeta = $fieldMeta;
$this->field = $field;
$this->fieldValue = $fieldValue;
}
protected function getImageMarkup(): string
{
$imageUrl = '';
$imageSize = $this->field->imageSize ?: 'full';
switch ($this->fieldMeta->getReturnFormat()) {
case 'id':
$imageUrl = function_exists('wp_get_attachment_image_url') ?
(string)wp_get_attachment_image_url($this->fieldValue, $imageSize) :
'';
break;
case 'array':
$sizes = (array)($this->fieldValue['sizes'] ?? []);
$imageUrl = $sizes[$imageSize] ?? '';
$imageUrl = ! $imageUrl ?
($this->fieldValue['url'] ?? '') :
$imageUrl;
break;
case 'url':
$imageUrl = $this->fieldValue;
break;
}
return "";
}
protected function getFileMarkup(): string
{
$fileUrl = '';
$fileTitle = '';
switch ($this->fieldMeta->getReturnFormat()) {
case 'id':
$fileUrl = function_exists('wp_get_attachment_url') ?
(string)wp_get_attachment_url($this->fieldValue) :
'';
$fileTitle = function_exists('get_post') ?
(get_post($this->fieldValue)->post_title ?? '') :
'';
break;
case 'array':
$fileUrl = $this->fieldValue['url'] ?? '';
$fileTitle = $this->fieldValue['title'] ?? '';
break;
case 'url':
$fileUrl = $this->fieldValue;
break;
}
// if the linkLabel is setup, use it instead of default
$fileTitle = $this->field->linkLabel ?: $fileTitle;
// use label in case there are no linkLabel and default
$fileTitle = ! $fileTitle ?
$this->field->label :
$fileTitle;
// last attempt to fill the label. Use the url
$fileTitle = ! $fileTitle ?
$fileUrl :
$fileTitle;
return "" . esc_html($fileTitle) . "";
}
protected function getSelectMarkup(): string
{
$fieldHTML = '';
// select & checkbox could have multiple values
$fieldValues = (is_array($this->fieldValue) &&
! key_exists('label', $this->fieldValue)) ?
$this->fieldValue :
[$this->fieldValue];
$fieldViews = [];
foreach ($fieldValues as $fieldValue) {
switch ($this->fieldMeta->getReturnFormat()) {
case 'value':
$fieldViews[] = $this->fieldMeta->getChoices()[$fieldValue] ?? '';
break;
case 'label':
$fieldViews[] = $fieldValue;
break;
case 'array':
$fieldViews[] = $fieldValue['label'] ?? '';
break;
}
}
if ('radio' === $this->fieldMeta->getType()) {
return implode('', $fieldViews);
}
foreach ($fieldViews as $subFieldView) {
$fieldHTML .= "