public function __construct($menu_term_slug) { parent::__construct(); $menu = wp_get_nav_menu_object($menu_term_slug); if (!empty($menu)) { $this->menu = $menu; $nav_menu_items = wp_get_nav_menu_items($this->menu->term_id); cfd_tmp_dbg('nav_menu_items_raw.txt', $nav_menu_items, 'print'); foreach ($nav_menu_items as $item) { $menu_item = wp_setup_nav_menu_item($item); $menu_item->metadata = get_metadata('post', $item->ID); foreach ($menu_item->metadata as $key => &$value) { $value[0] = maybe_unserialize($value[0]); } if ($menu_item->type == 'post_type') { $menu_item->parent = get_post($menu_item->metadata['_menu_item_object_id'][0]); } elseif ($menu_item->type == 'taxonomy' && (!property_exists($menu, 'object') || $menu->object != 'custom')) { $menu_item->term = get_term($menu_item->metadata['_menu_item_object_id'][0], $menu_item->metadata['_menu_item_object'][0]); } $this->items[] = $menu_item; } } else { throw new Exception(__('Invalid menu id', 'cf-deploy') . ': ' . esc_attr($menu_term_slug)); } }
public function __construct($post_id) { parent::__construct(); if (is_numeric($post_id)) { $_post = get_post(intval($post_id)); } elseif (is_object($post_id)) { $_post = $post_id; } elseif (is_array($post_id)) { if (isset($post_id['shallow_fetch'])) { $this->shallow_fetch = (bool) $post_id['shallow_fetch']; } if (!empty($post_id['guid'])) { // accept an array that specifies the guid $_post = $this->get_post_by_guid($post_id['guid']); } } if (!is_object($_post) || empty($_post->post_type)) { throw new Exception(sprintf(__('Could not retrieve post data for post: %s', 'cf-deploy'), print_r($post_id, true))); } $this->data['post'] = $_post; unset($_post, $post_id); $this->gather(); }