| | |
| | | |
| | | use JVBase\managers\SEO\render\Thing\Organization\LocalBusiness\LocalBusiness; |
| | | use JVBase\managers\SEO\render\Thing\Thing; |
| | | use JVBase\meta\Form; |
| | | use JVBase\meta\Meta; |
| | | use JVBase\registrar\fields\Field; |
| | | use JVBase\registrar\fields\GroupedField; |
| | | use JVBase\registrar\fields\OptionsField; |
| | |
| | | |
| | | class Fields { |
| | | protected array $fields; |
| | | protected Registrar $registrar; |
| | | private ?Registrar $registrar = null; |
| | | protected ?string $type; |
| | | |
| | | public function __construct(?string $type = null, ?Registrar $registrar = null) { |
| | | $this->registrar = $registrar; |
| | | $this->type = $type; |
| | | switch ($type) { |
| | | case 'post': |
| | | $this->addPostFields(); |
| | | //TODO: Add fields to post edit screen |
| | | // add_action('add_meta_boxes', [$this, 'registerPostFields']); |
| | | break; |
| | | case 'term': |
| | | $this->addTermFields(); |
| | |
| | | return $this; |
| | | } |
| | | |
| | | public function addPostFields():void |
| | | protected function defaultPostFields():array |
| | | { |
| | | $fields = [ |
| | | $statuses = [ |
| | | // 'all' => [ |
| | | // 'icon' => 'infinity', |
| | | // 'label' => 'Everything', |
| | | // ], |
| | | 'publish' => [ |
| | | 'icon' => 'eye', |
| | | 'label' => 'Live', |
| | | ], |
| | | 'draft' => [ |
| | | 'icon' => 'eye-closed', |
| | | 'label' => 'Hidden', |
| | | ], |
| | | 'trash' => [ |
| | | 'label' => 'Scrapped', |
| | | 'icon' => 'trash', |
| | | ], |
| | | // 'delete' => [ |
| | | // 'label' => 'Permanently Delete', |
| | | // 'icon' => 'trash' |
| | | // ] |
| | | ]; |
| | | if ($this->registrar->hasFeature('is_calendar')) { |
| | | $statuses = [ |
| | | 'future' => [ |
| | | 'icon' => '', |
| | | 'label' => 'Upcoming', |
| | | ], |
| | | 'past' => [ |
| | | 'icon' => '', |
| | | 'label' => 'Past', |
| | | ], |
| | | 'repeat' => [ |
| | | 'icon' => '', |
| | | 'label' => 'Repeating', |
| | | ], |
| | | 'draft' => [ |
| | | 'icon' => 'eye-closed', |
| | | 'label' => 'Hidden', |
| | | ], |
| | | 'trash' => [ |
| | | 'label' => 'Scrapped', |
| | | 'icon' => 'trash', |
| | | ], |
| | | ]; |
| | | } |
| | | return [ |
| | | 'post_status' => [ |
| | | 'type' => 'radio', |
| | | 'label' => 'Status', |
| | | 'default' => 'draft', |
| | | 'options' => $statuses |
| | | ], |
| | | 'post_thumbnail' => [ |
| | | 'type' => 'upload', |
| | | 'subtype' => 'image', |
| | | 'multiple'=> false, |
| | | 'label' => 'Main Image', |
| | | ], |
| | |
| | | 'type' => 'datetime', |
| | | 'label' => 'Date', |
| | | ], |
| | | 'post_modified' => [ |
| | | 'type' => 'datetime', |
| | | 'label' => 'Date Modified', |
| | | 'hidden' => true, |
| | | ], |
| | | 'post_content' => [ |
| | | 'type' => 'textarea', |
| | | 'quill' => true, |
| | |
| | | 'label' => 'TLDR', |
| | | 'maxLength' => 158, |
| | | ], |
| | | 'post_status' => [ |
| | | 'type' => 'radio', |
| | | 'label' => 'Status', |
| | | 'default' => 'draft', |
| | | 'options' => [ |
| | | 'all' => [ |
| | | 'icon' => 'infinity', |
| | | 'label' => 'Everything', |
| | | ], |
| | | 'publish' => [ |
| | | 'icon' => 'eye', |
| | | 'label' => 'Live', |
| | | ], |
| | | 'draft' => [ |
| | | 'icon' => 'eye-closed', |
| | | 'label' => 'Hidden', |
| | | ], |
| | | 'trash' => [ |
| | | 'label' => 'Scrapped', |
| | | 'icon' => 'trash', |
| | | ], |
| | | 'delete' => [ |
| | | 'label' => 'Permanently Delete', |
| | | 'icon' => 'trash' |
| | | ] |
| | | ] |
| | | ] |
| | | ]; |
| | | } |
| | | |
| | | public function addPostFields():void |
| | | { |
| | | $fields = $this->defaultPostFields(); |
| | | |
| | | foreach ($fields as $name => $config) { |
| | | $this->addField($name, $config); |
| | | } |
| | | } |
| | | |
| | | public function addTermFields():void |
| | | protected function defaultTermFields():array |
| | | { |
| | | $fields = [ |
| | | 'name' => [ |
| | |
| | | 'label' => 'Term Parent' |
| | | ]; |
| | | } |
| | | foreach ($fields as $name => $config) { |
| | | |
| | | return $fields; |
| | | } |
| | | |
| | | public function addTermFields():void |
| | | { |
| | | foreach ($this->defaultTermFields() as $name => $config) { |
| | | $this->addField($name, $config); |
| | | } |
| | | } |
| | | |
| | | public function addUserFields():void |
| | | protected function defaultUserFields():array |
| | | { |
| | | $fields = [ |
| | | return [ |
| | | 'first_name' => [ |
| | | 'type' => 'text', |
| | | 'label' => 'First Name', |
| | | 'section'=> 'your-account' |
| | | ], |
| | | 'last_name' => [ |
| | | 'type' => 'text', |
| | | 'label' => 'Last Name', |
| | | 'section'=> 'your-account' |
| | | ], |
| | | 'user_email' => [ |
| | | 'type' => 'email', |
| | | 'label' => 'Your Email', |
| | | 'section'=> 'your-account' |
| | | ], |
| | | 'display_name' => [ |
| | | 'type' => 'text', |
| | | 'label' => 'Display Name', |
| | | 'section'=> 'your-account' |
| | | ], |
| | | 'website' => [ |
| | | 'type' => 'url', |
| | | 'label' => 'Website', |
| | | ], |
| | | 'description' => [ |
| | | 'type' => 'textarea', |
| | | 'quill' => true, |
| | | 'label' => 'Description', |
| | | ] |
| | | // 'website' => [ |
| | | // 'type' => 'url', |
| | | // 'label' => 'Website', |
| | | // ], |
| | | // 'description' => [ |
| | | // 'type' => 'textarea', |
| | | // 'quill' => true, |
| | | // 'label' => 'Description', |
| | | // ], |
| | | ]; |
| | | foreach ($fields as $name => $config) { |
| | | } |
| | | public function addUserFields():void |
| | | { |
| | | foreach ($this->defaultUserFields() as $name => $config) { |
| | | $this->addField($name, $config); |
| | | } |
| | | } |
| | |
| | | $business = new LocalBusiness(); |
| | | $business->setHasOfferCatalogField($this); |
| | | } |
| | | |
| | | public function registerPostFields():void |
| | | { |
| | | $postType = $this->registrar->getBased(); |
| | | add_meta_box( |
| | | $postType.'_fields', |
| | | 'Extra Fields', |
| | | [$this, 'renderMyMetaBox'], |
| | | $postType, |
| | | 'side', |
| | | 'high' |
| | | ); |
| | | } |
| | | public function renderMyMetaBox():void |
| | | { |
| | | $ID = get_the_ID(); |
| | | $meta = match ($this->type) { |
| | | 'post' => Meta::forPost($ID), |
| | | 'term' => Meta::forTerm($ID), |
| | | 'user' => Meta::forUser($ID), |
| | | }; |
| | | $defaults = array_keys(match($this->type) { |
| | | 'post' => $this->defaultPostFields(), |
| | | 'term' => $this->defaultTermFields(), |
| | | 'user' => $this->defaultUserFields() |
| | | }); |
| | | foreach ($this->fields as $fName => $field){ |
| | | if (!in_array($fName, $defaults)){ |
| | | echo Form::render($fName, $meta->get($fName),$field->getConfig()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | public static function getUserFields():array |
| | | { |
| | | return (new self())->defaultUserFields(); |
| | | } |
| | | } |