label = $label; $this->key = $key; $this->fields = []; } /** * Registers a field. * * @access public * @param \AdvancedPostSearch\Field $field field * @return bool */ public function registerField(\AdvancedPostSearch\Field $field) { if (!in_array($field, $this->fields)) { $this->fields[] = $field; return true; } return false; } /** * Checks if a group is valid. * * @access public * @return bool */ public function isValid() { return ($this->key !== false); } /** * Gets a group attribute. * * @access public * @param string $key * @return mixed */ public function __get($key) { if (property_exists($this, $key)) { return $this->$key; } return null; } /** **************************************************************************************************** */ /** * Gets all ACF groups or a single grupp if key was specified. * * @access public * @static * @param mixed $key (default: null) * @return \AdvancedPostSearch\FieldGroup|array */ public static function get($key = null, $label = null) { if (is_string($key)) { $group = new self($key, $label); return ($group->isValid() ? $group : false); } return []; } /** **************************************************************************************************** */ }