protected function create_post(array $record) { $event = $this->build_event_array(false, $record); $id = Tribe__Events__API::createEvent($event); if ($this->is_aggregator && !empty($this->aggregator_record)) { Tribe__Events__Aggregator__Records::instance()->add_record_to_event($id, $this->aggregator_record->id, 'csv'); $this->aggregator_record->meta['activity']->add('event', 'created', $id); } return $id; }
protected function create_post(array $record) { $post_status_setting = Tribe__Events__Aggregator__Settings::instance()->default_post_status('csv'); $organizer = $this->build_organizer_array(false, $record); $id = Tribe__Events__API::createOrganizer($organizer, $post_status_setting); if ($this->is_aggregator && !empty($this->aggregator_record)) { $this->aggregator_record->meta['activity']->add('organizer', 'created', $id); } return $id; }
/** * Check to make sure that get_ical_link function works as expected * * @uses $post_example_settings */ public function test_get_ical_link_single() { global $post; $post = get_post(Tribe__Events__API::createEvent($this->post_example_settings)); $this->assertTrue($post instanceof WP_Post, 'Check that post creates properly'); $ical_link_single_via_object = Tribe__Events__iCal::get_ical_link('single'); $this->assertNotEmpty(filter_var($ical_link_single_via_object, FILTER_VALIDATE_URL), 'Checking that we get back a valid URL from object'); $ical_link_single_via_function = tribe_get_single_ical_link(); $this->assertNotEmpty(filter_var($ical_link_single_via_function, FILTER_VALIDATE_URL), 'Checking that we get back a valid URL from function'); $this->assertEquals($ical_link_single_via_object, $ical_link_single_via_function, 'Check that the function and object get the same result'); }
/** * Check to make sure that the event data is saved properly. * */ function test_tribe_create_event_API_meta_information() { $post = get_post(Tribe__Events__API::createEvent($this->postExampleSettings)); $this->assertEquals(3, $post->post_author); $this->assertEquals('This is event content!', $post->post_content); $this->assertEquals('', get_post_meta($post->ID, '_EventAllDay', true)); $this->assertEquals(1, get_post_meta($post->ID, '_EventHideFromUpcoming', true)); $this->assertEquals(5, get_post_meta($post->ID, '_EventOrganizerID', true)); $this->assertEquals(8, get_post_meta($post->ID, '_EventVenueID', true)); $this->assertEquals(1, get_post_meta($post->ID, '_EventShowMapLink', true)); $this->assertEquals(1, get_post_meta($post->ID, '_EventShowMapLink', true)); $this->assertEquals(1, get_post_meta($post->ID, '_EventShowMap', true)); $this->assertEquals('2012-01-03 15:25:00', get_post_meta($post->ID, '_EventEndDate', true)); }
/** * Sanitizes the data for the delete ticket ajax call, * and calls the child delete_ticket function. */ public final function ajax_handler_ticket_delete() { if (!isset($_POST["post_ID"])) { $this->ajax_error('Bad post'); } if (!isset($_POST["ticket_id"])) { $this->ajax_error('Bad post'); } if (empty($_POST["nonce"]) || !wp_verify_nonce($_POST["nonce"], 'remove_ticket_nonce') || !current_user_can('edit_tribe_events')) { $this->ajax_error("Cheatin' huh?"); } $post_id = $_POST["post_ID"]; $ticket_id = $_POST["ticket_id"]; // Pass the control to the child object $return = $this->delete_ticket($post_id, $ticket_id); // Successfully deleted? if ($return) { // Let's create a tickets list markup to return $tickets = $this->get_event_tickets($post_id); $return = Tribe__Events__Tickets__Tickets_Pro::instance()->get_ticket_list_markup($tickets); $return = $this->notice(__('Your ticket has been deleted.', 'the-events-calendar')) . $return; // Additionally ensure the event costs meta data is updated accordingly Tribe__Events__API::update_event_cost($post_id); } $this->ajax_ok($return); }
protected function create_post(array $record) { $venue = $this->build_venue_array($record); $id = Tribe__Events__API::createVenue($venue); return $id; }
protected function create_post(array $record) { $event = $this->build_event_array($record); $id = Tribe__Events__API::createEvent($event); return $id; }
/** * Performs the work of duplicating the TEC event * @return boolean */ function dte_duplicate_tribe_event() { if (!isset($_GET['_nonce']) || !wp_verify_nonce($_GET['_nonce'], 'dte_duplicate_event')) { return false; } $event_id = $_GET['post']; if (!class_exists('Tribe__Events__API')) { return false; } $event = (array) get_post($event_id); unset($event['ID']); // Remove ID to prevent an update from happening $event['post_status'] = 'draft'; $meta = get_post_custom($event_id); // Flatten out the meta array (WTF?) $fmeta = array(); foreach ($meta as $k => $v) { $fmeta[$k] = $v[0]; } // TEC expects a couple fields to exist without the _ upon creation $event['EventStartDate'] = date('Y-m-d', strtotime($fmeta['_EventStartDate'])); $event['EventStartHour'] = date('h', strtotime($fmeta['_EventStartDate'])); $event['EventStartMinute'] = date('i', strtotime($fmeta['_EventStartDate'])); $event['EventEndDate'] = date('Y-m-d', strtotime($fmeta['_EventEndDate'])); $event['EventEndHour'] = date('h', strtotime($fmeta['_EventEndDate'])); $event['EventEndMinute'] = date('j', strtotime($fmeta['_EventEndDate'])); // Unset recurrence to prevent potentially thousands of new events being created // This will also unlink an individual recurrence from its parent unset($fmeta['_EventRecurrence']); $event = array_merge($event, $fmeta); $new_event_id = Tribe__Events__API::createEvent($event); // Merge in any additional meta that may have been missed by createEvent foreach ($fmeta as $k => $v) { update_post_meta($new_event_id, $k, $v); } // Copy the taxonomies $taxonomies = get_object_taxonomies('tribe_events'); foreach ($taxonomies as $tax) { $terms = wp_get_object_terms($event_id, $tax); $term = array(); foreach ($terms as $t) { $term[] = $t->slug; } wp_set_object_terms($new_event_id, $term, $tax); } // Send back to the original page wp_redirect(admin_url("edit.php?post_type=tribe_events")); exit; }
/** * Preserves changed fields by resetting array indexes back to the stored post/meta values * * @param array $event Event array to reset * * @return array */ public static function preserve_changed_fields($event) { if (empty($event['ID'])) { return $event; } $post = get_post($event['ID']); $post_meta = Tribe__Events__API::get_and_flatten_event_meta($event['ID']); if (empty($post_meta[Tribe__Events__API::$modified_field_key])) { $modified = array(); } else { $modified = $post_meta[Tribe__Events__API::$modified_field_key]; } $post_fields_to_reset = array('post_title', 'post_content', 'post_status'); // reset any modified post fields foreach ($post_fields_to_reset as $field) { // don't bother resetting if the field hasn't been modified if (!isset($modified[$field])) { continue; } // don't bother resetting if we aren't trying to update the field if (!isset($event[$field])) { continue; } // don't bother resetting if we don't have a field to reset to if (!isset($post->{$field})) { continue; } $event[$field] = $post->{$field}; } $tec = Tribe__Events__Main::instance(); // reset any modified meta fields foreach ($tec->metaTags as $field) { // don't bother resetting if the field hasn't been modified if (!isset($modified[$field])) { continue; } // if we don't have a field to reset to, let's unset the event meta field if (!isset($post_meta[$field])) { unset($event[$field]); continue; } $event[$field] = $post_meta[$field]; } return $event; }
/** * Save the meta for the event if the user has the capability to. * * @return bool `true` if event meta was updated, `false` otherwise. */ public function save() { if (!$this->context->has_nonce()) { return false; } if (!$this->context->verify_nonce()) { return false; } if (!$this->context->current_user_can_edit_events()) { return false; } // Remove this hook to avoid an infinite loop, because saveEventMeta calls wp_update_post when the post is set to always show in calendar remove_action('save_post', array(Tribe__Events__Main::instance(), 'addEventMeta'), 15); $_POST['Organizer'] = isset($_POST['organizer']) ? stripslashes_deep($_POST['organizer']) : null; $_POST['Venue'] = isset($_POST['venue']) ? stripslashes_deep($_POST['venue']) : null; /** * handle previewed venues and organizers */ $this->manage_preview_metapost('venue', $this->post_id); $this->manage_preview_metapost('organizer', $this->post_id); Tribe__Events__API::saveEventMeta($this->post_id, $_POST, $this->post); // Add this hook back in add_action('save_post_' . Tribe__Events__Main::POSTTYPE, array(Tribe__Events__Main::instance(), 'addEventMeta'), 15, 2); return true; }
/** * Updates an venue * * @param int $venueId The venue ID to update. * @param array $data The venue data. * * @return void */ public static function updateVenue($venueId, $data) { $data['ShowMap'] = isset($data['ShowMap']) ? $data['ShowMap'] : 'false'; $data['ShowMapLink'] = isset($data['ShowMapLink']) ? $data['ShowMapLink'] : 'false'; Tribe__Events__API::saveVenueMeta($venueId, $data); do_action('tribe_events_venue_updated', $venueId, $data); }
/** * If a ticket is edited via the WooCommerce product editor (vs the ticket meta * box exposed in the event editor) then we need to trigger an update to ensure * cost meta in particular stays up-to-date on our side. * * @param $product_id */ public function syncronize_product_editor_changes($product_id) { $event = $this->get_event_for_ticket($product_id); // This product is not connected with an event if (!$event) { return; } // Trigger an update Tribe__Events__API::saveEventMeta($event->ID, array()); }
/** * Delete a Venue * * @param int $postId ID of the Venue to be deleted. * @param bool $force_delete Whether to bypass trash and force deletion. Defaults to false. * * @return bool false if delete failed. * @link http://codex.wordpress.org/Function_Reference/wp_delete_post * @see wp_delete_post() * @category Venues */ function tribe_delete_venue($postId, $force_delete = false) { $success = Tribe__Events__API::deleteVenue($postId, $args); return $success; }
/** * Make sure the organizer meta gets saved * * @param int $postID The organizer id. * @param WP_Post $post The post object. * * @return null|void */ public function save_organizer_data($postID = null, $post = null) { // was an organizer submitted from the single organizer post editor? if (empty($_POST['post_ID']) || $_POST['post_ID'] != $postID || empty($_POST['organizer'])) { return; } // is the current user allowed to edit this venue? if (!current_user_can('edit_tribe_organizer', $postID)) { return; } $data = stripslashes_deep($_POST['organizer']); Tribe__Events__API::updateOrganizer($postID, $data); }
/** * Delete an Organizer * * @param int $postId ID of the Organizer to be deleted. * @param bool $force_delete Whether to bypass trash and force deletion. Defaults to false. * * @return bool false if delete failed. * @link http://codex.wordpress.org/Function_Reference/wp_delete_post * @see wp_delete_post() * @category Organizers */ function tribe_delete_organizer($postId, $force_delete = false) { $success = Tribe__Events__API::deleteOrganizer($postId, $args); return $success; }
protected function create_post(array $record) { $organizer = $this->build_organizer_array(false, $record); $id = Tribe__Events__API::createOrganizer($organizer); return $id; }
/** * Delete an Event * * @param int $postId ID of the event to be deleted. * @param bool $force_delete Whether to bypass trash and force deletion. Defaults to false. * * @return bool false if delete failed. * @link http://codex.wordpress.org/Function_Reference/wp_delete_post * @see wp_delete_post() * @category Events */ function tribe_delete_event($postId, $force_delete = false) { $success = Tribe__Events__API::deleteEvent($postId, $force_delete); return $success; }