Created
May 12, 2016 13:42
-
-
Save borkweb/96bfab2120f6242c834e2b7423599061 to your computer and use it in GitHub Desktop.
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 | |
function convert_recurring_event_meta() { | |
global $wpdb; | |
// Get meta values | |
$event_recurrence_meta = $wpdb->get_results(" | |
SELECT post_id, meta_value | |
FROM $wpdb->postmeta | |
WHERE meta_key = '_EventRecurrence' | |
"); | |
// Update them | |
foreach ( $event_recurrence_meta as $event_recurrence_meta_item ) { | |
update_event_recurrence_meta( $event_recurrence_meta_item->post_id, $event_recurrence_meta_item->meta_value ); | |
} | |
} | |
/** | |
* Helper function to update event meta | |
*/ | |
function update_event_recurrence_meta( $post_id, $old_recurrence_value ) { | |
// Make sure value is unserialised | |
$old_recurrence_value = maybe_unserialize( $old_recurrence_value ); | |
// Skip if the recurrence data is already in the expected form | |
if ( count( $old_recurrence_value ) === 3 && ! empty( $old_recurrence_value['rules'] ) ) { | |
return; | |
} | |
$new_value = Tribe__Events__Pro__Recurrence__Meta::get_legacy_recurrence_meta( $post_id, $old_recurrence_value ); | |
// THIS NEEDS TO BE ADDED TO Tribe__Events__Pro__Recurrence__Meta::get_legacy_recurrence_meta() | |
if ( ! isset( $new_value['description'] ) && ! empty( $old_recurrence_value['recurrence-description'] ) ) { | |
$new_value['description'] = $old_recurrence_value['recurrence-description']; | |
} | |
// Update the meta | |
update_post_meta( $post_id, '_EventRecurrence', $new_value ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment