| | |
| | | <?php |
| | | namespace JVBase\meta; |
| | | |
| | | use DateTime; |
| | | use Exception; |
| | | use JVBase\utility\Features; |
| | | use WP_Post; |
| | | use JVBase\registrar\Registrar; |
| | | |
| | | if (!defined('ABSPATH')) { |
| | | exit; // Exit if accessed directly |
| | |
| | | case 'post': |
| | | $this->data = get_post((string)$ID); |
| | | $this->content = jvbNoBase($this->data->post_type); |
| | | $this->isTimeline = Features::forContent($this->content)->has('is_timeline'); |
| | | $registrar = Registrar::getInstance($this->content); |
| | | $this->isTimeline = $registrar && $registrar->hasFeature('is_timeline'); |
| | | break; |
| | | case 'term': |
| | | $this->data = get_term($ID); |
| | |
| | | $type = jvbUserRole((int)$this->object_id); |
| | | break; |
| | | case 'options': |
| | | return jvbGetFields('options'); |
| | | return Registrar::getFieldsFor('options'); |
| | | } |
| | | if (!$type) { |
| | | return []; |
| | | } |
| | | |
| | | $this->fields = jvbGetFields($type, $this->object_type); |
| | | $this->fields = Registrar::getFieldsFor($type); |
| | | return $this->fields; |
| | | } |
| | | |
| | |
| | | if (!$type) { |
| | | return []; |
| | | } |
| | | return jvbGetSections($type, $this->object_type); |
| | | return Registrar::getInstance($type)->getSections()??[]; |
| | | } |
| | | |
| | | protected function getRegistry():mixed |
| | | { |
| | | switch ($this->object_type) { |
| | | case 'post': |
| | | return JVB_CONTENT[jvbNoBase(get_post_type((int)$this->object_id))]??null; |
| | | case 'term': |
| | | $term = get_term((int)$this->object_id); |
| | | return JVB_TAXONOMY[jvbNoBase($term->taxonomy)]??null; |
| | | case 'user': |
| | | return JVB_USER; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * @param string $message |
| | |
| | | |
| | | } |
| | | if (empty($fields)) { |
| | | $fields = ($this->content) ? jvbGetFields($this->content, $this->object_type) : $this->getFields(); |
| | | $fields = ($this->content) ? Registrar::getFieldsFor($this->content) : $this->getFields(); |
| | | } |
| | | |
| | | if ($sections !== false && empty($sections)) { |
| | | |
| | | $sections = ($this->content) ? jvbGetSections($this->content, $this->object_type) : $this->getSections(); |
| | | $sections = ($this->content) ? Registrar::getInstance($this->content)->getSections() : $this->getSections(); |
| | | } |
| | | |
| | | if (!empty($sections)){ |
| | | $tabs = []; |
| | | foreach ($sections as $slug => $title) { |
| | | $tabs[$slug] = [ |
| | | 'title' => $title, |
| | | 'content' => '', |
| | | 'description' => jvbSectionDescription($slug)??'', |
| | | ]; |
| | | $icon = jvbSectionIcon($slug); |
| | | if ($icon !== '') { |
| | | $tabs[$slug]['icon'] = $icon; |
| | | } |
| | | foreach ($sections as $config) { |
| | | $tabs[$config['slug']] = $config; |
| | | } |
| | | } else { |
| | | $tabs = false; |