protected function create_post(array $record) { $this->hack_to_remove_broken_filters(); $venue = $this->build_venue_array($record); $id = TribeEventsAPI::createVenue($venue); return $id; }
protected function create_post(array $record) { $venue = $this->build_venue_array($record); $id = TribeEventsAPI::createVenue($venue); TribeEventsAPI::updateVenue($id, $venue); return $id; }
protected function create_post(array $record) { $organizer = $this->build_organizer_array($record); $id = TribeEventsAPI::createOrganizer($organizer); TribeEventsAPI::updateOrganizer($id, $organizer); return $id; }
/** * Check to make sure that the event data is saved properly. * * @since 2.0.5 * @author Paul Hughes */ function test_tribe_create_event_API_meta_information() { $post = get_post(TribeEventsAPI::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-01 01:15:00', get_post_meta($post->ID, '_EventStartDate', true)); $this->assertEquals('2012-01-03 15:25:59', get_post_meta($post->ID, '_EventEndDate', true)); }
/** * 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 Event Functions * @since 2.0.1 */ function tribe_delete_event($postId, $force_delete = false) { $success = TribeEventsAPI::deleteEvent($postId, $args); return $success; }
/** * Updates a venue */ public static function updateVenue($venueId, $data) { wp_update_post(array('post_title' => $data['Venue'], 'ID' => $venueId)); TribeEventsAPI::saveVenueMeta($venueId, $data); }
public function save_organizer_data($postID = null, $post = null) { global $_POST; // don't do anything on autosave or auto-draft either or massupdates // Or inline saves, or data being posted without a organizer Or // finally, called from the save_post action, but on save_posts that // are not organizer posts if (!isset($_POST['organizer'])) { $_POST['organizer'] = null; } if (wp_is_post_autosave($postID) || $post->post_status == 'auto-draft' || isset($_GET['bulk_edit']) || isset($_REQUEST['action']) && $_REQUEST['action'] == 'inline-save' || !$_POST['organizer'] || $post->post_type != self::ORGANIZER_POST_TYPE && $postID) { return; } if (!current_user_can('edit_tribe_organizers')) { return; } //There is a possibility to get stuck in an infinite loop. //That would be bad. remove_action('save_post', array($this, 'save_organizer_data'), 16, 2); $data = stripslashes_deep($_POST['organizer']); $organizer_id = TribeEventsAPI::updateOrganizer($postID, $data); /** * Put our hook back * @link http://codex.wordpress.org/Plugin_API/Action_Reference/save_post#Avoiding_infinite_loops */ add_action('save_post', array($this, 'save_organizer_data'), 16, 2); return $organizer_id; }
/** * 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'; TribeEventsAPI::saveVenueMeta($venueId, $data); do_action('tribe_events_venue_updated', $venueId, $data); }
/** * 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) { global $current_screen; if (!empty($current_screen) && $current_screen->id == 'tribe_organizer') { // single organizer $_POST['Organizer'] = isset($_POST['organizer']) ? stripslashes_deep($_POST['organizer']) : null; } // Don't save the organizer meta if there wasn't one submitted if (empty($_POST['Organizer'])) { return; } // @TODO move this to the API function if (!current_user_can('edit_tribe_organizers')) { return; } $data = stripslashes_deep($_POST['Organizer']); TribeEventsAPI::updateOrganizer($postID, $data); }
function import_meetup_events($atts) { $fetched = 0; $found = 0; $created = 0; $updated = 0; $content = ''; //$content .= '<p>Remote host: ' . $_SERVER["REMOTE_ADDR"] . '</p>'; $host = $_SERVER["REMOTE_ADDR"]; $local_ip = getHostByName(getHostName()); if (!current_user_can('manage_options') && $local_ip != $host) { $content .= '<div class="bimbler-alert-box error"><span>Error: </span>You must be an admin user to view this page.</div>'; error_log('import_meetup_events called by non-admin or not from localhost.'); return $content; } $a = shortcode_atts(array('api_key' => 7, 'group_id' => 0, 'create_if_not_found' => 'N', 'update_meta_if_found' => 'N', 'test' => 'Y'), $atts); if (!isset($a)) { error_log('import_meetup_events called with no parameters set.'); $content .= '<div class="bimbler-alert-box error"><span>Error: </span>No parameters specified.</div>'; return $content; } //error_log ('Post vars: ' . json_encode ($_POST)); if (isset($_POST['bimbler-run-job'])) { error_log('Run job clicked.'); $a['test'] = 'N'; } // Work around the UTC bug... date_default_timezone_set('Australia/Brisbane'); $date_from = date('Y-m-d', strtotime($a['ahead'] . ' days')); $date_to = date('Y-m-d', strtotime($a['ahead'] + 1 . ' days')); $content .= '<h5>Input Parameters</h5>'; $content .= 'Group ID: ' . $a['group_id'] . '<br>'; $content .= 'API Key: ' . $a['api_key'] . '<br>'; $content .= 'Test mode: ' . $a['test'] . '<br>'; $content .= 'Create new: ' . $a['create_if_not_found'] . '<br>'; $content .= 'Update meta: ' . $a['update_meta_if_found'] . '<br><br>'; $output = ''; // What does this app do today? $create_if_not_found = false; $update_meta_if_found = false; if ('Y' == $a['create_if_not_found']) { $create_if_not_found = true; } if ('Y' == $a['update_meta_if_found']) { $update_meta_if_found = true; } $test_mode = false; if ('Y' == $a['test']) { $test_mode = true; } $import = $this->fetch_meetup_events($a['group_id'], $a['api_key']); // Who are are running as? $this_user_id = $this->get_current_user_id(); //$content .= 'Running as user ID: ' . $this_user_id . '<br><br>'; $content .= '<h4>Output:</h4>'; $content .= $import->output; $content .= '<br>'; $fetched = count($import->events); $content .= 'Fetched ' . $fetched . ' events.<br>'; if ($fetched > 0) { $i = 1; foreach ($import->events as $event) { // Create new member, containing parsed date. $event->event_date = date('Y-m-d H:i:s', $this->get_event_date($event)); $content .= $i++ . ': ' . $event->id . ' -> ' . $event->name . ' on ' . $event->event_date; // $content .= '<br>'; // See if this event already exists. $get_posts = tribe_get_events(array('eventDisplay' => 'custom', 'posts_per_page' => 1, 'post_status' => array('publish', 'draft'), 'meta_query' => array(array('key' => '_EventStartDate', 'value' => $event->event_date, 'compare' => '=', 'type' => 'datetime')), 'tax_query' => array(array('taxonomy' => TribeEvents::TAXONOMY, 'field' => 'slug', 'terms' => 'mingle')))); $content .= ' --'; //error_log (json_encode ($get_posts)); // Got the same event (or at least, *a* Mingle starting at the same time). if (!empty($get_posts)) { $found++; $this_event = $get_posts[0]; //$content .= '<pre>' . json_encode ($this_event, true) . '</pre>'; // $content .= ' Found: ' . $this_event->post_title . ' on ' . tribe_get_start_date($this_event->ID, false, 'Y-m-d H:i:s') . '.'; $content .= ' Found: post ID <a href="' . get_permalink($this_event->ID) . '" target="_external">' . $this_event->ID . '</a>.<br>'; // We're updating existing events - backfill data. if ($update_meta_if_found) { // Event found, but not with a Meetup ID. if (!get_post_meta($this_event->ID, 'bimbler_meetup_id', true)) { if (!$test_mode) { // Update with Meetup ID if it's not already set update_post_meta($this_event->ID, 'bimbler_meetup_id', $event->id); $content .= '<font color="orange"> -- Updated Meetup ID.</font> '; } else { $content .= '<font color="orange"> -- Test mode - Meetup ID not updated. </font>'; } $updated++; } else { $content .= '<font color="green"> -- Existing event with Meetup ID set - no action to take.</font>'; // See if we need to update date / time. // Can't do this, as the query loop is searching by date / time. /* $curr_start_date = tribe_get_start_date($event->ID, false, 'Y-m-d H:i:s'); $curr_end_date = tribe_get_end_date($event->ID, false, 'Y-m-d H:i:s'); if ($curr_start_date != $event->event_date) { $content .= ' Meetup start time not same as here (' . $curr_start_date . ' -> ' . $event->event_date); } */ } } else { $content .= '<font color="green"> -- Not running in "Update Meetup ID if found" mode - no action taken.</font>'; } } else { // No mingler event found at that time on that day. if ($create_if_not_found) { //$content .= '<pre>' . print_r ($event, true) . '</pre>'; //$new_event = new stdClass(); $new_event = array(); $new_event['EventStartDate'] = date('Y-m-d', strtotime($event->event_date)); $new_event['EventStartHour'] = date('h', strtotime($event->event_date)); $new_event['EventStartMinute'] = date('i', strtotime($event->event_date)); if (isset($event->duration)) { //$content .= ' Adding ' . $event->duration / 1000 . ' seconds '; $new_event['EventEndDate'] = date('Y-m-d', strtotime($event->event_date . ' + ' . $event->duration / 1000 . ' seconds')); $new_event['EventEndHour'] = date('h', strtotime($event->event_date . ' + ' . $event->duration / 1000 . ' seconds')); $new_event['EventEndMinute'] = date('i', strtotime($event->event_date . ' + ' . $event->duration / 1000 . ' seconds')); } else { // Add an abitrary 2 hours to the start time to get the end time. $new_event['EventEndDate'] = date('Y-m-d', strtotime($event->event_date . ' + 2 hours')); $new_event['EventEndHour'] = date('h', strtotime($event->event_date . ' + 2 hours')); $new_event['EventEndMinute'] = date('i', strtotime($event->event_date . ' + 2 hours')); } $content .= '<br><font color="red"> -- Creating new event.</font>'; //$content .= '<pre>' . print_r ($new_event, true) . '</pre>'; $new_event['post_status'] = 'draft'; $new_event['author'] = $this_user_id; $new_event['post_title'] = $event->name; $new_event['post_content'] = $event->description; // XXXXX REMOVE SECOND TERM WHEN FINISHED TESTING XXXX //if (!$test_mode && ($created < 1)) { if (!$test_mode) { $new_event_id = TribeEventsAPI::createEvent($new_event); // 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); } // Update with Meetup ID. update_post_meta($new_event_id, 'bimbler_meetup_id', $event->id); $tribe_ecp = TribeEvents::instance(); // Set this to a Mingle. $term_info = get_term_by('slug', 'mingle', $tribe_ecp->get_event_taxonomy()); wp_set_object_terms($new_event_id, $term_info->term_id, $term_info->taxonomy); $content .= ' New event ID: <a href="' . get_permalink($new_event_id) . '" target="_external">' . $new_event_id . '</a>'; } else { $content .= '<font color="orange"> -- Test mode - Event not created. </font>'; } $created++; } else { // End create_if_not_found. $content .= '<font color="green"><br> -- Not running in "Create if not found" mode - no action taken.</font>'; } } $content .= '<br>'; } } $summary = 'import_meetup_events: fetched: ' . $fetched . ', found: ' . $found . ', created: ' . $created . ', updated: ' . $updated . '.'; $content .= '<br>' . $summary; error_log($summary); return $content; }
protected function create_post(array $record) { $event = $this->build_event_array($record); $id = TribeEventsAPI::createEvent($event); return $id; }
/** * 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']); TribeEventsAPI::updateOrganizer($postID, $data); }
/** * 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) { wp_update_post(array('post_title' => $data['Venue'], 'ID' => $venueId)); $data['ShowMap'] = isset($data['ShowMap']) ? $data['ShowMap'] : 'false'; $data['ShowMapLink'] = isset($data['ShowMapLink']) ? $data['ShowMapLink'] : 'false'; TribeEventsAPI::saveVenueMeta($venueId, $data); do_action('tribe_events_venue_updated', $venueId, $data); }
/** * 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 = TribeEventsTicketsPro::instance()->get_ticket_list_markup($tickets); $return = $this->notice(__('Your ticket has been deleted.', 'tribe-events-calendar')) . $return; // Additionally ensure the event costs meta data is updated accordingly TribeEventsAPI::update_event_cost($post_id); } $this->ajax_ok($return); }
/** * Convert Venue data * * @param string $post */ private static function convertVenue($post) { $venue = array(); foreach (self::$legacyVenueTags as $tag) { $strippedTag = str_replace('_Event', '', $tag); $meta = get_post_meta($post->ID, $tag, true); $venue[$strippedTag] = $meta; delete_post_meta($post->ID, $tag); } if ($venue['Country'] == 'United States') { $venue['StateProvince'] = get_post_meta($post->ID, '_EventState', true); } else { $venue['StateProvince'] = get_post_meta($post->ID, '_EventProvince', true); } $unique_venue = $venue['Venue'] . $venue['Address'] . $venue['StateProvince']; if ($unique_venue && trim($unique_venue) != "") { if (!isset(self::$curVenues[$unique_venue])) { self::$curVenues[$unique_venue] = TribeEventsAPI::createVenue($venue); } else { TribeEventsAPI::updateVenue(self::$curVenues[$unique_venue], $venue); } update_post_meta($post->ID, '_EventVenueID', self::$curVenues[$unique_venue]); } }
/** * Save an existing event. * * @param int $tribe_event_id The event's ID. * @return int The saved event's ID. * @author Nick Ciske * @since 1.0 */ public function saveEvent($tribe_event_id) { $saved = TribeEventsAPI::updateEvent($tribe_event_id, $_POST); $this->save_submitted_attachment($tribe_event_id); // TODO: why aren't we saving taxonomy terms like in createEvent()? return $saved; }