• Hi,

    Working from this tutorial (which works great)
    http://www.stephenharris.info/2012/front-end-event-posting/

    But trying to to update posts as well… all working except that cant figure why the dates are not being saved in the format: 16-Jul-2013 12:00am doesnt datetime obj dupport that?

    <?php
    /**
     * This is a basic example of implementing front end creation of events with Event Organiser
     * @see http://www.stephenharris.info/2012/front-end-event-posting/
     * @see http://wordpress.org/extend/plugins/event-organiser/
     *
    */
    add_shortcode('my_event_form','my_event_form_shortcode_handler');
    
    function my_event_form_shortcode_handler( ){
    
    	if( !is_user_logged_in() ){
    		return '<p> Only logged in users can post events </p>';
    	}
    
    	// =T. Get Post Data for Event Updates
    	$event_id = $_GET['event_id']; // get event id form url like url?event_id
    	$event_post = $event_id ? get_post($event_id) : null;
    	$event_start_date = eo_get_schedule_start( 'd-M-Y h:ia', $event_id );
    	$event_end_date = eo_get_schedule_last('d-M-Y h:ia', $event_id );
    
    	// The form
    	$html .= '<form method="POST">';
    
    	// pass event_id if updating and event
    	$html .= $event_id ? '<input type="hidden"	name="my_frontend_event[event_id]" value="'.$event_id.'" >' : '';
    
    	//Create hidden 'action' field and corresponding nonce
    	$html .= '<input type="hidden"	name="my-action" value="post-event" >';
    	$html .=wp_nonce_field( 'post-event', '_mynonce',false,false);
    
    	//Event Title
    	$html .= sprintf('<p><label for="my-frontend-event-%1$s"> %2$s
    				<input type="text" name="my_frontend_event[%1$s]" id="my-frontend-event-%1$s" value="%3$s">
    			</label></p>',
    			'title',
    			'Event Title',
    			$event_post->post_title
    		);
    
    	//Event Description
    	$html .= sprintf('<p><label for="my-frontend-event-%1$s"> %2$s
    				<textarea name="my_frontend_event[%1$s]" id="my-frontend-event-%1$s">%3$s</textarea>
    			</label></p>',
    			'description',
    			'Event Description',
    			$event_post->post_content
    		);
    
    	//Start date
    	$html .= sprintf('<p><label for="my-frontend-event-%1$s"> %2$s
    				<input type="text" name="my_frontend_event[%1$s]" id="my-frontend-event-%1$s" class="my-frontend-event-datepicker" value="%3$s" >
    			</label></p>',
    			'startdate',
    			'Start Date',
    			$event_start_date
    		);
    
    	//End date
    	$html .= sprintf('<p><label for="my-frontend-event-%1$s"> %2$s
    				<input type="text" name="my_frontend_event[%1$s]" id="my-frontend-event-%1$s" class="my-frontend-event-datepicker" value="%3$s" >
    			</label></p>',
    			'enddate',
    			'End Date',
    			$event_end_date
    		);
    
    	//The post button
    	$html .= '<p><input name="submit" type="submit" id="submit" value="Post Event"></p>';
    
    	$html .='</form>';
    
    	return $html;
    
    }
    
    add_action('init','my_frontend_event_post_listner');
    function my_frontend_event_post_listner(){
    
    	if( !isset($_POST['my-action']) || 'post-event' != $_POST['my-action'] )
    		return;
    
    	//Collect raw input
    	$input = $_POST['my_frontend_event'];
    
    	//Check user is logged in:
    	if( !is_user_logged_in() )
    		return;
    
    	//Check nonce
    	check_admin_referer( 'post-event',  '_mynonce');
    
    	$post_data =array(
    		'post_title'=>$input['title'],
    		'post_content'=>$input['description'],
            'post_status' => 'pending'
    	);
    
    	/**
    	 * Set the event data
    	*/
    	//Start and end dates need to be given as DateTime objects (timezone is UTC unless a timezone is given)
    	$start = new DateTime($input['startdate'], eo_get_blog_timezone());
    	$end = new DateTime($input['enddate'], eo_get_blog_timezone());
    	$event_data =array(
    		'schedule' =>'once',  //specifies the reoccurrence pattern
    		'all_day' =>  0, //1 if its an all day event, 0 if not - if not you'll need to specify a start/end time for the DateTimeobjects
    		'start' =>  $start, //start date (of first occurrence)  as a datetime object
    		'end' => $end,  //end date (of first occurrence)  as a datetime object
    	);
    
    	//Finally, Insert event.
    
    	if ($input['event_id']) {
    		$post_id = eo_update_event($input['event_id'], $event_data, $post_data );
    	} else {
    		$post_id = eo_insert_event ($post_data,$event_data);
    	}
    
    	if ($post_id) {
    		wp_redirect( home_url('/dashboard/my-events'));
    		exit;
    	}
    
    }
    ?>
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Stephen Harris

    (@stephenharris)

    “16-Jul-2013 12:00am” should be valid as an input: http://wp-event-organiser.com/documentation/relative-date-formats/?phprelativedate=16-Jul-2013%2012:00am

    I would first check the what you’re giving eo_update_events():

    wp_die(var_dump($event_data));

    And check it all makes sense and then go from there.

    Thread Starter TiagoPires

    (@tiasch)

    Hi Stephan!

    This is the $event_data using var_export($event_data) just before eo_update_event()

    Array (
    	[schedule] => once
    	[all_day] => 0
    	[start] => DateTime Object (
    		[date] => 2013-07-21 10:00:00
    		[timezone_type] => 3
    		[timezone] => Australia/Sydney
    	)
    	[end] => DateTime Object (
    		[date] => 2013-07-22 10:00:00
    		[timezone_type] => 3
    		[timezone] => Australia/Sydney
    	)
    )

    Thanks for the help!

    Thread Starter TiagoPires

    (@tiasch)

    Creating events works fine, dates and everything… just having problems to updated the dates when updating an event. They do update title, descriptions etc…

    Plugin Author Stephen Harris

    (@stephenharris)

    That function should either return the event ID or a WP_Error message. From what I can tell there is a minor bug in the update function in that you’re not specifying a schedule last date – though it shouldn’t be necessary in that case. Providing the schedule last date (set it to the start date) it should work fine. I’ll be fixing that in the next update, but the work-around is to make sure you specify a ‘schedule last’ date when updating.

    Also, in the above keep in mind eo_get_schedule_last() is not the end date as you have it. It is the data of the start of the last occurrence of that event. In this case, a single occurrence event, it is the same as the start date. See http://codex.wp-event-organiser.com/function-eo_get_event_schedule.html. Also, http://codex.wp-event-organiser.com/function-eo_get_the_occurrences_of.html.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Update Event’ is closed to new replies.