/** * Sets an array with only the mf2 prefixed meta. * * @param int|WP_Post $post Optional. Post ID or post object. Defaults to global $post. */ private function get_mf2meta($post) { $post = get_post($post); $meta = get_post_meta($post->ID); if (!$meta) { $this->meta = array(); return; } if (isset($meta['response'])) { $response = maybe_unserialize($meta['response']); // Retrieve from the old response array and store in new location. if (!empty($response)) { $new = array(); // Convert to new format and update. if (!empty($response['title'])) { $new['name'] = $response['title']; } if (!empty($response['url'])) { $new['url'] = $response['url']; } if (!empty($response['content'])) { $new['content'] = $response['content']; } if (!empty($response['published'])) { $new['published'] = $response['published']; } if (!empty($response['author'])) { $new['card'] = array(); $new['card']['name'] = $response['author']; if (!empty($response['icon'])) { $new['card']['photo'] = $response['icon']; } } $new = array_unique($new); $new['card'] = array_unique($new['card']); if (isset($new)) { update_post_meta($this->post->ID, 'mf2_cite', $new); delete_post_meta($this->post->ID, 'response'); $meta['cite'] = $new; } } } foreach ($meta as $key => $value) { if (!str_prefix($key, 'mf2_')) { unset($meta[$key]); } else { unset($meta[$key]); $key = str_replace('mf2_', '', $key); $value = array_map('maybe_unserialize', $value); $value = array_shift($value); // If value is a multi-array with only one element. if (is_multi_array($value)) { if (1 === count($value)) { $value = array_shift($value); } if (isset($value['card'])) { if (is_multi_array($value['card'])) { if (1 === count($value['card'])) { $value['card'] = array_shift($value['card']); } } $value['card'] = array_filter($value['card']); } } if (is_array($value)) { $value = array_filter($value); } $meta[$key] = $value; } } $this->meta = array_filter($meta); }
/** * Add a product to the cart * @todo: Add optionnal VAT attribute * * @param string|array $id Unique ID of the product|Item formated as array|Array of items * @param string $name * @param int $qty * @param double $price * @param array $options * * @return self */ public function add($id, $name = null, $qty = null, $price = null, array $options = []) { if (is_array($id)) { // And if it's not only an array, but a multidimensional array, we need to // recursively call the add function is_multi_array($id) ? $this->addMany($id) : $this->addOne($id); } else { $this->fireEvent('add', $data = compact('id', 'name', 'qty', 'price', 'options')); $this->addProduct($id, $name, $qty, $price, $options); $this->fireEvent('added', $data); } return $this; }