/** * Fetches the JSON-LD data for this type of object * * @param int|WP_Post|null $post The post/venue * @param array $args * @return array */ public function get_data($post = null, $args = array('context' => false)) { $data = parent::get_data($post, $args); // If we have an Empty data we just skip if (empty($data)) { return array(); } // Fetch first key $post_id = key($data); // Fetch first Value $data = reset($data); $data->address = array(); $data->address['streetAddress'] = tribe_get_address($post_id); $data->address['addressLocality'] = tribe_get_city($post_id); $data->address['addressRegion'] = tribe_get_region($post_id); $data->address['postalCode'] = tribe_get_zip($post_id); $data->address['addressCountry'] = tribe_get_country($post_id); // Filter empty entries and convert to object $data->address = (object) array_filter($data->address); $geo = tribe_get_coordinates($post_id); if (!empty($geo['lat']) && !empty($geo['lng'])) { $data->geo = (object) array('@type' => 'GeoCoordinates', 'latitude' => $geo['lat'], 'longitude' => $geo['lng']); } $data->telephone = tribe_get_phone($post_id); $data->sameAs = tribe_get_venue_website_url($post_id); return array($post_id => $data); }
/** * Fetches the JSON-LD data for this type of object * * @param int|WP_Post|null $post The post/organizer * @param array $args * @return array */ public function get_data($post = null, $args = array('context' => false)) { $data = parent::get_data($post, $args); // If we have an Empty data we just skip if (empty($data)) { return array(); } // Fetch first key $post_id = key($data); // Fetch first Value $data = reset($data); $data->telephone = tribe_get_organizer_phone($post_id); $data->email = tribe_get_organizer_email($post_id); $data->sameAs = tribe_get_organizer_website_url($post_id); return array($post_id => $data); }
/** * Fetches the JSON-LD data for this type of object * * @param int|WP_Post|null $post The post/event * @param array $args * @return array */ public function get_data($posts = null, $args = array()) { $posts = $posts instanceof WP_Post ? array($posts) : (array) $posts; $return = array(); foreach ($posts as $i => $post) { $data = parent::get_data($post, $args); // If we have an Empty data we just skip if (empty($data)) { continue; } // Fetch first key $post_id = key($data); // Fetch first Value $data = reset($data); $event_tz_string = get_post_meta($post_id, '_EventTimezone', true); $tz_mode = tribe_get_option('tribe_events_timezone_mode', 'event'); $tz_string = $event_tz_string && $tz_mode === 'event' ? $event_tz_string : Tribe__Events__Timezones::wp_timezone_string(); $data->startDate = Tribe__Events__Timezones::to_utc(tribe_get_start_date($post_id, true, Tribe__Date_Utils::DBDATETIMEFORMAT), $tz_string, 'c'); $data->endDate = Tribe__Events__Timezones::to_utc(tribe_get_end_date($post_id, true, Tribe__Date_Utils::DBDATETIMEFORMAT), $tz_string, 'c'); if (tribe_has_venue($post_id)) { $venue_id = tribe_get_venue_id($post_id); $venue_data = Tribe__Events__JSON_LD__Venue::instance()->get_data($venue_id); $data->location = reset($venue_data); } if (tribe_has_organizer($post_id)) { $organizer_id = tribe_get_organizer_id($post_id); $organizer_data = Tribe__Events__JSON_LD__Organizer::instance()->get_data($organizer_id); $data->organizer = reset($organizer_data); } $price = tribe_get_cost($post_id); $price = $this->normalize_price($price); if ('' !== $price) { // Manually Include the Price for non Event Tickets $data->offers = (object) array('@type' => 'Offer', 'price' => $price, 'url' => $data->url); } $return[$post_id] = $data; } return $return; }
/** * Empties the registered posts cache variable. * * Added for testing purposes. */ public static function unregister_all() { self::$posts = array(); }