| | |
| | | <?php |
| | | namespace JVBase\meta; |
| | | |
| | | use JVBase\base\Options; |
| | | use JVBase\registrar\Registrar; |
| | | use WP_Post; |
| | | use WP_Term; |
| | |
| | | /** |
| | | * Create Meta instance for options |
| | | */ |
| | | public static function forOptions(?string $baseKey = 'ajv'): self |
| | | public static function forOptions(?string $baseKey = BASE): self |
| | | { |
| | | if (array_key_exists($baseKey, self::$instances['options'])) { |
| | | return self::$instances['options'][$baseKey]; |
| | |
| | | |
| | | $registrar = !is_null($this->slug) ? Registrar::getInstance($this->slug) : false; |
| | | $fields = $registrar ? $registrar->getFields() : []; |
| | | if ($this->type == 'options') { |
| | | $options = Options::getInstance(); |
| | | $fields = $options->getFields(); |
| | | } |
| | | $meta = match($type) { |
| | | 'post' => get_post_meta($id), |
| | | 'term' => get_term_meta($id), |
| | |
| | | } |
| | | if (!array_key_exists($name, $this->fields)) { |
| | | error_log('[Meta]::get Attempted to get unregistered field: '.$name); |
| | | return ''; |
| | | } |
| | | if (is_null($this->fields[$name])) { |
| | | error_log('[Meta]::get Field does not seem to be setup yet: '.$name); |
| | | return ''; |
| | | } |
| | | return $this->fields[$name]->get()??''; |
| | | } |