Creative solution to overwrite/sync issues?

WordPress Event Management, Calendars & Registration Forums iCal Extension Creative solution to overwrite/sync issues?

This topic contains 1 reply, has 2 voices, and was last updated by  Stephen Harris 8 years, 7 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #22449

    I’m using the iCal extension on a site for a client, a non-profit organization with a busy calendar.

    Basically:
    They have an older calendaring system which some of their staff use. Their entire calendar, in fact, is initially imputed into that calendar. (It’s hosted elsewhere.)

    I use the iCal extension to import the events into their website. It syncs frequently (as we’ve set it) and works flawlessly.

    Here’s the challenge:
    If the even doesn’t have a description entered in the legacy calendar, they can enter and edit text in the WordPress event. When it syncs, the new text is preserved since the original event (from the feed) has no data in that field.

    But: If they add a description in WordPress, and then someone edits the description in the source calendar (even if they type something and then delete it), the feed now has description content for that event. So when the calendar syncs a few minutes later, any text entered in WordPress is overwritten by the feed.

    To be clear: the extension is doing what it’s supposed to do. This is a problem with my client’s office workflow, not the plugin.

    I’m wondering:
    Is there a way to set the extension to not sync specific fields (notably the description field) on future imports? I’d love to set it so that if the field has content entered in WordPress, it stops syncing. Or even better: a checkbox on the event’s edit page that when selected causes the extension not to input data from the external feed.

    Is this even possible? And if so, how complex would it be for me to implement? (I’m not against writing a plugin, though I have to admit I’m a front end designer who’s more comfortable with CSS than PHP.)

    Obviously my client could solve the problem by simply making sure their staff doesn’t touch the description field in the old calendar system once an event is entered and present in the feed. But despite training and explanations and warnings, the overwrite thing keeps happening. So I’d love to offer them a solution that gives them a sense of control over this.

    Thanks!

    Josh Mason-Barkin
    #22452

    Hi Josh,

    The plug-in uses eo_update_event() (codex) to update events. So you can use the filter eventorganiser_update_event_post_data (you’ll have to dig into the source code for details).

    That filter will be probably be deprecated in the future, but is unlikely to be ever removed. Now, that will be empty when updating an event using the admin UI, but in any case, you probably want to be be able to determine whether that filter is being triggered as the result of importing a feed.

    There’s no clean way to do this but the filter eventorganiser_ical_sync_meta_key_map is triggered before each event is updated and the eventorganiser_ical_sync_meta_key_map option is updated once the feed has been processed.

    That would allow you to set a flag (e.g. use a global variable):

    global $do_ical_feed;
    $do_ical_feed=true;
    

    in your eventorganiser_ical_sync_meta_key_map callback and then check for that in your eventorganiser_update_event_post_data callback:

    /**
     * Filters the event's data (that relates to the wp_posts table) to be updated 
     * We remove the post_content key if present, when doing an iCal feed
     * so that it is not updated.
     */
    add_filter( 'eventorganiser_update_event_post_data', function( $post_data ) {
        global $do_ical_feed;
        if ( $do_ical_feed && $post_data ) {
               unset( $post_data['post_content'] ); 
         }
        return $post_data;
    }, 10, 1 );
    

    Then use the pre_update_option_eventorganiser_ical_sync_meta_key_map hook to unset the flag.

    In a future version of this plugin I’ll add a couple of filters so that you can add/remove data being passed to eo_insert_event() and eo_update_event() which is a might tidier solution..

    Stephen Harris
Viewing 2 posts - 1 through 2 (of 2 total)
To enable me to focus on Pro customers, only users who have a valid license for the Pro add-on may post new topics or replies in this forum. If you have a valid license, please log-in or register an account using the e-mail address you purchased the license with. If you don't you can purchase one here. Or there's always the WordPress repository forum.