Last active
March 5, 2020 17:35
-
-
Save jsit/98524a8ba4a97b9fd8db to your computer and use it in GitHub Desktop.
Allow WP All Import to create events with Events Manager
This file contains hidden or 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
// Create a proper EM_Event object in the database when an event-type post is | |
// imported with WP All import | |
add_action('pmxi_saved_post', 'post_saved', 10, 1); | |
function post_saved($post_id) { | |
if (class_exists(EM_Event)) { | |
$event_post = get_post($post_id); | |
// Only create a new event entry if the imported post is of type event and | |
// there is not an existing event for this post | |
$existing_event = em_get_event($event_post->ID, 'post_id'); | |
if ($event_post->post_type == 'event' && empty($existing_event->event_id)) { | |
add_filter('em_event_can_manage', 'force_can_manage', 10, 1); | |
$event = new EM_Event(); | |
$event->load_postdata($event_post); | |
$event->save(); | |
remove_filter('em_event_can_manage', 'force_can_manage'); | |
} | |
} | |
} | |
function force_can_manage($boolean) { | |
return true; | |
} |
This doesn't work on cron imports, if "Allow anonymous event submissions?" is set to "No" in Events Manager settings, due to the permissions check on line 632 of classes/em-event.php
.
Added force_can_manage
, which fixes problem with cron imports.
If I can get this working, it will really save my Bacon! I'm getting an HTTP Error 500 when I add this to my themes functions.php.
Any help will be greatly appreciated!
James
Hi,
i'm very interesting by this snippet, but where do i paste it ? In wpallimport function area or in theme functions.php ?
Thank's
Hi, Jay!
Great job, its work well!
But could you help me to change (or add) this snippet to work with EM_Location?
like this
- Create a new location entry if the imported post is of type event and location dosn't exist (create _location_id).
- Load 3 custom fields to Location post type (EM_Location):
_location_name
_location_address
_location_country.
Custom fields already exist when a event-type in WP All import.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This doesn't work on cron imports, for some reason; I'm looking into it.