Additional Overwrite options
WordPress Event Management, Calendars & Registration › Forums › iCal Extension › Additional Overwrite options
This topic contains 12 replies, has 2 voices, and was last updated by Stephen Harris 8 years, 6 months ago.
-
AuthorPosts
-
April 22, 2016 at 8:35 pm #22489
I read the previous post regarding preventing specific Post data overwrites. We have a similar situation, but different circumstances.
We setup the ical feed to pull each feed from Google into a WP Category. That works well. After we received the data, we apply updates to the event. Specifically, we add a thumbnail and a second “special” category to some events that we want to feature. The next time the feed runs, our client suggests he’s seeing inconsistent activity. Specifically:
- The event updates, the “special” category remains intact, and the featured image remains intact
- The event updates, the “special” category is no longer checked, but the featured image IS still there.
- The event updates, but both the category and the featured image are gone.
I can only reproduce activity from situation #2. After briefly reviewing your code, I can’t see how situations #1 and #3 could occur, but I may have overlooked something. It appears that when the feed is associated with a category, as is the case with all of our feeds, it will overwrite any categories previously present with the new category ($cats = array( $category );). Lastly, I do not see where the code could delete the thumbnail meta data.
In response, I have the following questions:
- Do you think situations #1 and #3 are possible? If so, can you provide a code snippet, like the previous post, that will prevent updating specific post meta data, i.e. Category and Thumbnail.
- If the category update needs to work as it does now, we can either add a new custom field to the event post type or use tags. In either case, I want to confirm that the meta data won’t reset.
- If options 1 and 2 aren’t possible, do you have a suggestion regarding how we might be able to manage the thumbnails and/or special event types?
Thank you,
MartenMarten QuadlandApril 26, 2016 at 5:34 pm #22539I can see 1 and 3 potentially occurring.
Specifically thumbnails are not imported/updated by the plugin, so I can’t see how it would be removed.
However, importing a feed could overwrite the category. If the event has one or more categories in the feed it will override the events current category. If it doesnt ,it will do nothing, This is in fact a bug: in such instances it should remove existing categories.
So depending on how your code handles updated events, I think 1 and 3 could occur.
Metadata is updated but not removed (it should arguably remove it if not present). But the only meta key registered by core is for the a URL custom field
I think the underlying issue is that the hooks for adding/updating an event from a feed are fired too early. Specifically they are fired before venues/categories/meta are updated.
Really it should fire after so you can retrospectively add a category or assign a thumbnail.
Can you provide the code you are using, as that will help me see how you’re handling feed updates now.
Stephen HarrisApril 26, 2016 at 6:49 pm #22540Stephen,
We do not currently have any custom code that handles feed updates, just the main Event plugin and the iCal Feed plugin.
On the General event setting tab, we’ve enabled :
Organiser ( Author )
Thumbnail
Excerpt
Custom Fields
Revisions
Event TagsOn the ICal Import/Export Tab, we added feeds with:
Name, Google Calendar slug, Assigned Event to author, Category, and Event Status (either set to “Use status specified in feed” or “Published”, I’m not sure what the difference is b/t the two)
After we receive the feed, we add the thumbnail, tag, and/or category.
Ideally, I am looking for a hook and code sample to ensure we don’t update the thumbnail and tag. Regarding the category, the client has some feeds that they would like to associate with more than one category. In those case, I figured we could hard code the exceptions in the theme function.php file.
Marten QuadlandApril 26, 2016 at 8:00 pm #22541I see, this is a manual process.
Thumbnails and tags should be unaffected. Categories will be trickier but I shall see what can be done.
R.e. status – iCal feeds can have their own status (confirmed, tentative etc) these will be mapped to publish / draft / trash etc or you can assign a status.
Stephen HarrisApril 26, 2016 at 8:06 pm #22542Regarding categories, thank you.
FYI, I’m not sure it matters, but I want to clarify that we have the sync scheduled for “Once Hourly”. In other words, we’re expecting the data to update on a regular basis.
Marten QuadlandApril 28, 2016 at 3:49 pm #22571Stephen,
Checking in to see if you had any luck with the categories.
Thanks.
Marten QuadlandApril 29, 2016 at 6:49 pm #22588Stephen,
Can you give me a sense of when you will be able to look into the categories? We’re hoping to launch the site this weekend and this is the last piece of functionality that we are waiting on.
Thank you.
Marten QuadlandApril 29, 2016 at 11:01 pm #22590Hi Marten,
The only solution I can see is to move the hooks
eventorganiser_ical_sync_event_updated
andeventorganiser_ical_sync_event_inserted
to immediately beneath this line:if ( $cats ) { wp_set_object_terms( $event_id, $cats, 'event-category' ); }
(~line 507), and trigger either depending on whether an event is being created or updated:
if ( $found_event ) { do_action( 'eventorganiser_ical_sync_event_updated', $event_id, $event, $feed_id ); } else { do_action( 'eventorganiser_ical_sync_event_inserted', $event_id, $event, $feed_id ); }
That will be included in the next update. What this allows you to do is to update an event to add the ‘special’ category:
add_action( 'eventorganiser_ical_sync_event_updated', function ( $event_id ) { $cats = wp_get_object_terms( $event_id, 'event-category', array( 'fields' => 'ids' ) ); if ( /* event had 'special category' */ ) { $cats[] = 123; //change to ID of 'special 'category' wp_set_object_terms( $event_id, $cats, 'event-category' ); } }, 10 );
(you’ll need to specify the term ID of the ‘special’ category. The only problem to solve is how to check an event had a special category (as it would have been removed with the sync).
One way to do that is to hook into
save_post
and check if the event has that category, if so, add a post meta to act a ‘flag’, and if not, delete it (if it exists). You can use a check for the existence of that flag as the conditiona..Stephen HarrisMay 6, 2016 at 5:59 pm #22674Stephen,
Thank you, your code helps.
The client recently expanded their request to prevent removing categories that they add for the event and prevent updating the event as whole.
Regarding preventing the sync from updating the categories they add, I’m not clear what you mean by hooking into the “save_post”. On the other hand, I believe I have a simple fix to your code to accomplish what we need. I merely changed:
wp_set_object_terms( $event_id, $cats, 'event-category' );
to
wp_set_object_terms( $event_id, $cats, 'event-category', true );
That allows the category to append without overriding the updates applied since the last sync.
It would be nice to provide an override feature to prevent updating specific fields or the event as a whole. If you see a better way, please let me know.
If there is a good reason to avoid doing what we want to do, please let me know.
Thank you.
Marten QuadlandMay 6, 2016 at 7:54 pm #22675The client recently expanded their request to prevent removing categories that they add for the event and prevent updating the event as whole.
So they want to allow the importer to importer the event, and then leave it completely alone?
Regarding the solution you proposed, unfortunately this won’t work in general. That would append the category terms to the event. If the categories in the iCal feed change then they will be added, but the original categories in the feed not removed. Similarly if the categories are removed from the iCal feed, that won’t be reflected after the next sync.
If you wanted to prevent the sync from doing anything to already-imported events then you can add the line
continue;
in between these two lines:$parsed_events[] = $event_id; update_post_meta( $event_id, '_eventorganiser_feed', $feed_id );
I’m happy to insert a filter that in the next update to make it possible to do that without editing the plug-in files.
Stephen HarrisMay 6, 2016 at 8:09 pm #22676Stephen,
Thank you, that is very helpful. If you could provide the filter, that would be great.
Regarding my proposed Category solution, to clarify, that would only be an issue if we set the feed to use the “categories specified in the feed”, correct? If so, that won’t be an issue for us because we are setting each feed to a specific category.
Regards
Marten QuadlandMay 9, 2016 at 1:31 pm #22685That’s correct (though obviously maybe an issue for other users).
There’ll be an update for the filter at some point next week.
Stephen HarrisMay 30, 2016 at 11:37 pm #229162.2 has just been released. It add the
eventorganiser_ical_sync_update_event
filter that allows you to prevent events from being updated in a sync:add_filter( 'eventorganiser_ical_sync_update_event', '__return_false' );
The
eventorganiser_ical_sync_event_inserted
andeventorganiser_ical_sync_event_updated
hooks have been moved so that the they are triggered after the event categories / venues / meta data has been updated.Stephen Harris -
AuthorPosts