Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save alexnnnn/aafe9310a8636d1b04a9391fe5929e43 to your computer and use it in GitHub Desktop.
Save alexnnnn/aafe9310a8636d1b04a9391fe5929e43 to your computer and use it in GitHub Desktop.
Allow WP All Import to create events with Events Manager
// 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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment