<?php
|
namespace JVBase\registrar\fields;
|
|
use JVBase\registrar\Registrar;
|
|
if (!defined('ABSPATH')) {
|
exit;
|
}
|
|
class SelectorField extends Field {
|
protected string $taxonomy;
|
protected string $post_type;
|
protected string $user_role;
|
protected int $max = 0;
|
protected bool $search = true;
|
protected bool $createNew = false;
|
protected bool $autocomplete = true;
|
/**
|
* @var bool isReference If true, does not set default taxonomy functionality, but is a reference to the selected items. (example: if it's a taxonomy subtype, does not set_object_terms with the selection)
|
*/
|
protected bool $isReference = false;
|
protected bool $update = true;
|
protected string $subtype;
|
protected array $allowedSubtype = ['taxonomy', 'user', 'post'];
|
|
public function setTaxonomy(string $taxonomy):void
|
{
|
$allowed = array_merge(['tag', 'category'], Registrar::getRegistered('term'));
|
if (!in_array(jvbNoBase($taxonomy), $allowed)) {
|
error_log('[SelectorField]Attempted taxonomy not allowed: '.$taxonomy);
|
return;
|
}
|
$this->taxonomy = $taxonomy;
|
}
|
public function getTaxonomy():string {
|
return $this->taxonomy;
|
}
|
|
public function setPost_type(string $post_type):void
|
{
|
$allowed = array_merge(['post', 'page'], Registrar::getRegistered('post'));
|
if (!in_array(jvbNoBase($post_type), $allowed)) {
|
error_log('[SelectorField]Attempted post type not allowed: '.$post_type);
|
return;
|
}
|
$this->post_type = $post_type;
|
}
|
public function getPost_type():string {
|
return $this->post_type;
|
}
|
|
public function setUser_role(string $user_role):void
|
{
|
$allowed = array_merge(['administrator'], Registrar::getRegistered('user'));
|
if (!in_array(jvbNoBase($user_role), $allowed)) {
|
error_log('[SelectorField]Attempted user not allowed: '.$user_role);
|
return;
|
}
|
$this->user_role = $user_role;
|
}
|
public function getUser_role():string {
|
return $this->user_role;
|
}
|
|
public function setMax(int $max):void
|
{
|
$this->max = $max;
|
}
|
public function getMax():int
|
{
|
return $this->max;
|
}
|
public function setSearch(bool $search):void {
|
$this->search = $search;
|
}
|
public function getSearch():bool
|
{
|
return $this->search;
|
}
|
public function setCreateNew(bool $createNew):void
|
{
|
$this->createNew = $createNew;
|
}
|
public function getCreateNew():bool
|
{
|
return $this->createNew;
|
}
|
public function setAutocomplete(bool $autocomplete):void
|
{
|
$this->autocomplete = $autocomplete;
|
}
|
public function getAutocomplete():bool
|
{
|
return $this->autocomplete;
|
}
|
public function setUpdate(bool $update):void
|
{
|
$this->update = $update;
|
}
|
public function getUpdate():bool
|
{
|
return $this->update;
|
}
|
public function setSubtype(string $subtype):void
|
{
|
if (!in_array($subtype, $this->allowedSubtype)) {
|
error_log('[SelectorField]Attempted subtype not allowed: '.$subtype);
|
return;
|
}
|
$this->subtype = $subtype;
|
}
|
public function getSubtype():string
|
{
|
return $this->subtype;
|
}
|
|
public function setIsReference(bool $isReference):void
|
{
|
$this->isReference = $isReference;
|
}
|
public function getIsReference():bool
|
{
|
return $this->isReference;
|
}
|
}
|