| 1 |
<?php |
| 2 |
|
| 3 |
namespace ImportWP\Common\AddonAPI\Importer\Template; |
| 4 |
|
| 5 |
class CustomFields |
| 6 |
{ |
| 7 |
private $_name; |
| 8 |
private $_prefix; |
| 9 |
private $_fields = []; |
| 10 |
|
| 11 |
public function __construct($name, $prefix) |
| 12 |
{ |
| 13 |
$this->_name = $name; |
| 14 |
$this->_prefix = $prefix; |
| 15 |
} |
| 16 |
|
| 17 |
public function get_prefix() |
| 18 |
{ |
| 19 |
return $this->_prefix; |
| 20 |
} |
| 21 |
|
| 22 |
public function register_field($name, $args = []) |
| 23 |
{ |
| 24 |
$id = isset($args['id']) ? $args['id'] : sanitize_title($name); |
| 25 |
$type = isset($args['type']) ? $args['type'] : 'text'; |
| 26 |
|
| 27 |
$this->_fields[$id] = [ |
| 28 |
'id' => $id, |
| 29 |
'name' => $name, |
| 30 |
'type' => $type |
| 31 |
]; |
| 32 |
} |
| 33 |
|
| 34 |
public function get_dropdown_fields() |
| 35 |
{ |
| 36 |
|
| 37 |
$tmp_fields = []; |
| 38 |
foreach ($this->_fields as $field_id => $field) { |
| 39 |
|
| 40 |
$tmp_fields[] = [ |
| 41 |
'value' => $this->_prefix . '::' . $field['type'] . '::' . $field_id, |
| 42 |
'label' => $this->_name . ' - ' . $field['name'] |
| 43 |
]; |
| 44 |
} |
| 45 |
|
| 46 |
return $tmp_fields; |
| 47 |
} |
| 48 |
|
| 49 |
public function get_fields() |
| 50 |
{ |
| 51 |
return $this->_fields; |
| 52 |
} |
| 53 |
|
| 54 |
public function get_field($field_id) |
| 55 |
{ |
| 56 |
return isset($this->_fields[$field_id]) ? $this->_fields[$field_id] : false; |
| 57 |
} |
| 58 |
} |
| 59 |
|