Example #1
1
 /**
  * Create an Event
  *
  * $args accepts all the args that can be passed to wp_insert_post().
  * In addition to that, the following args can be passed specifically
  * for the process of creating an Event:
  *
  * - EventStartDate date string (required) - Start date of the Event.
  * - EventEndDate date string (required) - End date of the Event.
  * - EventAllDay bool - Set to true if event has no start / end time and should run all day.
  * - EventStartHour string - Event start hour (01 - 12).
  * - EventStartMinute string - Event start minute (01 - 60).
  * - EventStartMeridian string - Event start meridian (am or pm).
  * - EventEndHour string - Event end hour (01 - 12).
  * - EventEndMinute string - Event end minute (01 - 60).
  * - EventEndMeridian string - Event end meridian (am or pm).
  * - EventHideFromUpcoming bool - Set to true to hide this Event from the upcoming list view.
  * - EventShowMapLink bool - Set to true to display a link to the map in the Event view.
  * - EventShowMap bool - Set to true to embed the map in the Event view.
  * - EventCost string - Default cost of the Event.
  * - Venue array - Array of data to create or update an Venue to be associated with the Event. {@link tribe_create_venue}.
  * - Organizer array - Array of data to create or update an Organizer to be associated with the Event. {@link tribe_create_organizer}.
  *
  * Note: If ONLY the 'VenueID'/'OrganizerID' value is set in the 'Venue'/'Organizer' array,
  * then the specified Venue/Organizer will be associated with this Event without attempting
  * to edit the Venue/Organizer. If NO 'VenueID'/'OrganizerID' is passed, but other Venue/Organizer
  * data is passed, then a new Venue/Organizer will be created.
  *
  * Also note that this function can be used only for the creation of events, supplying
  * a post_type argument therefore is superfluous as it will be reset to the events post
  * type in any case.
  *
  * @param array $args Elements that make up post to insert.
  *
  * @return int ID of the event that was created. False if insert failed.
  * @link     http://codex.wordpress.org/Function_Reference/wp_insert_post
  * @see      wp_insert_post()
  * @see      tribe_create_venue()
  * @see      tribe_create_organizer()
  * @category Events
  */
 function tribe_create_event($args)
 {
     $args['post_type'] = Tribe__Events__Main::POSTTYPE;
     $postId = Tribe__Events__API::createEvent($args);
     return $postId;
 }
 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;
 }
 /**
  * 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));
 }
 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;
}