Skip to content

Instantly share code, notes, and snippets.

@jaredatch
Created February 8, 2018 16:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaredatch/d368c1a243c14a3f10cbb5c2f9754d56 to your computer and use it in GitHub Desktop.
Save jaredatch/d368c1a243c14a3f10cbb5c2f9754d56 to your computer and use it in GitHub Desktop.
WPForms manually run the 1.4.3 entries database upgrade routine
<?php
/**
* Manually run the v1.4.3 entries upgrade routine.
*
*/
function wpf_v143_upgrade_manual() {
// Fetch all entries.
$entries = wpforms()->entry->get_entries(
array(
'number' => -1,
'order' => 'ASC',
)
);
// Loop through the entries and add each field value to the new entry
// fields database table.
if ( ! empty( $entries ) ) {
foreach ( $entries as $entry ) {
$fields = wpforms_decode( $entry->fields );
if ( ! empty( $fields ) ) {
foreach ( $fields as $field ) {
if ( isset( $field['id'] ) && isset( $field['value'] ) && '' !== $field['value'] ) {
wpforms()->entry_fields->add(
array(
'entry_id' => absint( $entry->entry_id ),
'form_id' => absint( $entry->form_id ),
'field_id' => absint( $field['id'] ),
'value' => $field['value'],
'date' => $entry->date,
)
);
}
}
}
}
}
delete_option( 'wpforms_fields_update' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment