protected function _get_fields() { if ($this->_fields == null || count($this->_fields) < count($this->_fields_init)) { foreach ($this->_fields_init as $_key => $field_init) { if (array_key_exists($_key, $this->_fields)) { continue; } list($key, $title, $field) = $field_init; if ($field == null) { $this->_fields[$key] = new Text(); } elseif (is_string($field)) { $this->_fields[$key] = FieldFactory::build($field); } elseif (Action::is_callable($field)) { $this->_fields[$key] = Action::execute($field); if (!$this->_fields[$key] instanceof AbstractField) { throw new WpException("Meta box field \"{$title}\" init function must return a Field."); } } else { throw new WpException("Invalid field type."); } $this->_fields[$key]->set_name($key); $this->_fields[$key]->set_label($title); } } return $this->_fields; }
/** * Get taxonomy field * * @return AbstractField * @throws WpException */ public function get_field() { if ($this->_field == null) { if ($this->_field_init == null) { $this->_field = new Text(); } elseif (is_string($this->_field_init)) { $this->_field = FieldFactory::build($this->_field_init); } elseif (Action::is_callable($this->_field_init)) { $this->_field = Action::execute($this->_field_init); if (!$this->_field instanceof AbstractField) { throw new WpException("Option \"{$this->_title}\" init function must return a Field."); } } else { throw new WpException("Invalid field type."); } $this->_field->set_name($this->_key); $this->_field->set_label($this->_title); } return $this->_field; }
/** * @param $key * @param $title * @param null $field * @return AbstractField * @throws \WPKit\Exception\WpException */ protected function _add_field($key, $title, $field = null) { $key = sanitize_key($key); if ($field == null) { $this->_fields[$key] = new Text(); } elseif (is_string($field)) { $this->_fields[$key] = FieldFactory::build($field); } elseif (Action::is_callable($field)) { $this->_fields[$key] = Action::execute($field); if (!$this->_fields[$key] instanceof AbstractField) { throw new WpException("Widget field \"{$title}\" init function must return a Field."); } } else { throw new WpException("Invalid field type."); } $this->_fields[$key]->set_id($this->get_field_id($key)); $this->_fields[$key]->set_name($this->get_field_name($key), false); $this->_fields[$key]->set_label($title); return $this->_fields[$key]; }