Created
April 17, 2018 08:45
-
-
Save andrasguseo/27ffab2085a516f8c0c5c1283d7eaf44 to your computer and use it in GitHub Desktop.
Modify / remove event venue when importing with EA (The Events Calendar)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Description: Removes the venue details from the imported event | |
* Note: Once the event, venue. etc are imported it forces PRO | |
* to recalculate the venue coords via Google | |
* | |
* Usage: modify the URL at the end of the code based on your needs | |
* | |
* Version: 1.0 | |
* Plugins: The Events Calendar (Event Aggregator) | |
* Author: Barry Hughes | |
* Last updated: April 17, 2018 | |
* | |
* Changelog: | |
* Version 1.0 (April 17, 2018) | |
* - Initial release | |
*/ | |
class Imported_Events_Address_Modifier { | |
protected $source; | |
public function __construct( $source ) { | |
$this->source = $source; | |
} | |
public function __invoke( $event, $record ) { | |
# Only run if the event is being imported from the specified source | |
if ( $this->source === null || $this->source === $record->meta['source'] ) { | |
add_action( | |
'tribe_events_update_meta', | |
[ $this, 'post_creation' ] | |
); | |
} | |
return $event; | |
} | |
public function post_creation( $event_id ) { | |
# Run once only | |
remove_action( | |
'tribe_events_update_meta', | |
[ $this, 'post_creation' ] | |
); | |
$venue_id = tribe_get_venue_id( $event_id ); | |
if ( empty( $venue_id ) ) { | |
return; | |
} | |
# This sets the geoaddress to the same value as the venue title | |
update_post_meta( $venue_id, '_VenueGeoAddress', get_the_title( $venue_id ) ); | |
# Wipe other address fields | |
update_post_meta( $venue_id, '_VenueAddress', '' ); | |
update_post_meta( $venue_id, '_VenueCity', '' ); | |
update_post_meta( $venue_id, '_VenueCountry', '' ); | |
update_post_meta( $venue_id, '_VenueState', '' ); | |
update_post_meta( $venue_id, '_VenueZip', '' ); | |
# If PRO is active, try to re-encode via Google | |
if ( class_exists( 'Tribe__Events__Pro__Geo_Loc' ) ) { | |
Tribe__Events__Pro__Geo_Loc::instance()->save_venue_geodata( $venue_id, array() ); | |
} | |
} | |
} | |
function modify_imported_event_address( $source_feed = null ) { | |
$modifier = new Imported_Events_Address_Modifier( $source_feed ); | |
add_filter( 'tribe_aggregator_before_insert_event', $modifier, 10, 2 ); | |
} | |
# Providing no param/setting the first param to null means this operates | |
# on all sources (Facebook, CSV, Meetup, etc) | |
# Sample to operate on all sources | |
modify_imported_event_address(); | |
# Sample to operate on a specific source | |
# If you would like to use this for more sources, then make a copy of the | |
# below line for each source. | |
# modify_imported_event_address( 'https://domain.com/crm/events/party-calendar.ics' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment