fieldId = $fieldId; $this->name = ''; $this->type = ''; $this->returnFormat = ''; $this->choices = []; $this->fieldData = $fieldData; $this->isFieldExist = false; $this->displayFormat = ''; $this->read(); } private function getPostFieldData(): array { $fieldData = [ 'name' => $this->fieldId, ]; switch ($this->fieldId) { case Post::FIELD_TITLE: case Post::FIELD_AUTHOR: case Post::FIELD_DATE: case Post::FIELD_MODIFIED: $fieldData['type'] = 'text'; break; case Post::FIELD_THUMBNAIL: $fieldData['type'] = 'image'; $fieldData['return_format'] = 'id'; break; } return $fieldData; } private function getFieldData(): array { if ($this->fieldData) { return $this->fieldData; } if (in_array($this->fieldId, Post::getFields(), true)) { return $this->getPostFieldData(); } if (! function_exists('get_field_object')) { return $this->fieldData; } $fieldData = get_field_object($this->fieldId); return $fieldData ? (array)$fieldData : []; } private function read(): void { $fieldData = $this->getFieldData(); $this->name = (string)($fieldData['name'] ?? ''); $this->type = (string)($fieldData['type'] ?? ''); $this->returnFormat = (string)($fieldData['return_format'] ?? ''); $this->choices = (array)($fieldData['choices'] ?? ''); $this->displayFormat = (string)($fieldData['display_format'] ?? ''); $this->isFieldExist = ! ! $this->type; } public function getFieldId(): string { return $this->fieldId; } public function getName(): string { return $this->name; } public function getType(): string { return $this->type; } public function getReturnFormat(): string { return $this->returnFormat; } public function getDisplayFormat(): string { return $this->displayFormat; } public function getChoices(): array { return $this->choices; } public function isFieldExist(): bool { return $this->isFieldExist; } }