/** * Format the value of the property before it's returned * to WordPress admin or the site. * * @param mixed $value * @param string $slug * @param int $post_id * * @return array */ public function format_value($value, $slug, $post_id) { if (!is_array($value)) { return []; } $value = parent::format_value($value, $slug, $post_id); return array_shift($value); }
/** * Prepare properties. * * Not the best name for this function, but since * property repeater using this we can't rename it. * * @param array $layouts * * @return array */ protected function prepare_properties($layouts) { $layouts = array_map(function ($layout) { return (array) $layout; }, $layouts); foreach ($layouts as $index => $layout) { if (!$this->valid_layout($layout)) { if (is_array($layout)) { unset($layout[$index]); } else { unset($layouts[$index]); } continue; } if (!isset($layout['slug'])) { $layout['slug'] = $layout['title']; } $layouts[$index]['slug'] = papi_slugify($layout['slug']); $layouts[$index]['slug'] = $this->get_layout_value($layouts[$index]['slug']); $layouts[$index]['items'] = parent::prepare_properties($layout['items']); } return array_filter($layouts); }