|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Understory; |
| 4 | + |
| 5 | +use Timber; |
| 6 | + |
| 7 | +class MenuItem extends Timber\MenuItem implements MetaDataBinding |
| 8 | +{ |
| 9 | + public function getBindingName() |
| 10 | + { |
| 11 | + return $this->post_type; |
| 12 | + } |
| 13 | + |
| 14 | + /** |
| 15 | + * Implentation of MetaDataBinding::getMetaValue |
| 16 | + * |
| 17 | + * @param string $key Key for the meta field |
| 18 | + * @return string Value of the meta field |
| 19 | + */ |
| 20 | + public function getMetaValue($key) |
| 21 | + { |
| 22 | + return \get_post_meta($this->ID, $key, true); |
| 23 | + } |
| 24 | + |
| 25 | + /** |
| 26 | + * Implentation of MetaDataBinding::setMetaValue |
| 27 | + * |
| 28 | + * @param string $key Key for the meta field |
| 29 | + * @param string $value Value for the meta field |
| 30 | + */ |
| 31 | + public function setMetaValue($key, $value) |
| 32 | + { |
| 33 | + \update_post_meta($this->ID, $key, $value); |
| 34 | + } |
| 35 | + |
| 36 | + /** |
| 37 | + * Order of method calls: |
| 38 | + * |
| 39 | + * 1. getMethodName($args) |
| 40 | + * 2. methodName($args) |
| 41 | + * 3. propertyName |
| 42 | + * 4. fall back to Timber's core implementation |
| 43 | + * |
| 44 | + * @param string $propertyName |
| 45 | + * @param array $args |
| 46 | + * @return mixed |
| 47 | + */ |
| 48 | + public function __call($propertyName, $args = []) |
| 49 | + { |
| 50 | + if (method_exists($this, 'get'.$propertyName)) { |
| 51 | + return call_user_func_array([$this, 'get'.$propertyName], $args); |
| 52 | + } else if (method_exists($this, $propertyName)) { |
| 53 | + return call_user_func_array([$this, $propertyName], $args); |
| 54 | + } else if (property_exists($this, $propertyName)) { |
| 55 | + return $this->$propertyName; |
| 56 | + } |
| 57 | + |
| 58 | + return parent::__call($propertyName, $args); |
| 59 | + } |
| 60 | +} |
0 commit comments