block-editor
3 years ago
css
3 years ago
js
3 years ago
swv
3 years ago
capabilities.php
7 years ago
config-validator.php
3 years ago
contact-form-functions.php
3 years ago
contact-form-template.php
3 years ago
contact-form.php
3 years ago
controller.php
3 years ago
file.php
3 years ago
form-tag.php
3 years ago
form-tags-manager.php
3 years ago
formatting.php
3 years ago
functions.php
3 years ago
html-formatter.php
3 years ago
integration.php
3 years ago
l10n.php
3 years ago
mail.php
3 years ago
pipe.php
4 years ago
pocket-holder.php
3 years ago
rest-api.php
4 years ago
shortcodes.php
3 years ago
special-mail-tags.php
3 years ago
submission.php
3 years ago
upgrade.php
7 years ago
validation-functions.php
3 years ago
validation.php
3 years ago
upgrade.php
86 lines
| 1 | <?php |
| 2 | |
| 3 | add_action( 'wpcf7_upgrade', 'wpcf7_convert_to_cpt', 10, 2 ); |
| 4 | |
| 5 | function wpcf7_convert_to_cpt( $new_ver, $old_ver ) { |
| 6 | global $wpdb; |
| 7 | |
| 8 | if ( ! version_compare( $old_ver, '3.0-dev', '<' ) ) { |
| 9 | return; |
| 10 | } |
| 11 | |
| 12 | $old_rows = array(); |
| 13 | |
| 14 | $table_name = $wpdb->prefix . "contact_form_7"; |
| 15 | |
| 16 | if ( $wpdb->get_var( "SHOW TABLES LIKE '$table_name'" ) ) { |
| 17 | $old_rows = $wpdb->get_results( "SELECT * FROM $table_name" ); |
| 18 | } elseif ( $opt = get_option( 'wpcf7' ) |
| 19 | and ! empty( $opt['contact_forms'] ) ) { |
| 20 | foreach ( (array) $opt['contact_forms'] as $key => $value ) { |
| 21 | $old_rows[] = (object) array_merge( |
| 22 | $value, |
| 23 | array( 'cf7_unit_id' => $key ) |
| 24 | ); |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | foreach ( (array) $old_rows as $row ) { |
| 29 | $q = "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_old_cf7_unit_id'" |
| 30 | . $wpdb->prepare( " AND meta_value = %d", $row->cf7_unit_id ); |
| 31 | |
| 32 | if ( $wpdb->get_var( $q ) ) { |
| 33 | continue; |
| 34 | } |
| 35 | |
| 36 | $postarr = array( |
| 37 | 'post_type' => 'wpcf7_contact_form', |
| 38 | 'post_status' => 'publish', |
| 39 | 'post_title' => maybe_unserialize( $row->title ), |
| 40 | ); |
| 41 | |
| 42 | $post_id = wp_insert_post( $postarr ); |
| 43 | |
| 44 | if ( $post_id ) { |
| 45 | update_post_meta( $post_id, '_old_cf7_unit_id', $row->cf7_unit_id ); |
| 46 | |
| 47 | $metas = array( 'form', 'mail', 'mail_2', 'messages', 'additional_settings' ); |
| 48 | |
| 49 | foreach ( $metas as $meta ) { |
| 50 | update_post_meta( $post_id, '_' . $meta, |
| 51 | wpcf7_normalize_newline_deep( maybe_unserialize( $row->{$meta} ) ) ); |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | add_action( 'wpcf7_upgrade', 'wpcf7_prepend_underscore', 10, 2 ); |
| 58 | |
| 59 | function wpcf7_prepend_underscore( $new_ver, $old_ver ) { |
| 60 | if ( version_compare( $old_ver, '3.0-dev', '<' ) ) { |
| 61 | return; |
| 62 | } |
| 63 | |
| 64 | if ( ! version_compare( $old_ver, '3.3-dev', '<' ) ) { |
| 65 | return; |
| 66 | } |
| 67 | |
| 68 | $posts = WPCF7_ContactForm::find( array( |
| 69 | 'post_status' => 'any', |
| 70 | 'posts_per_page' => -1, |
| 71 | ) ); |
| 72 | |
| 73 | foreach ( $posts as $post ) { |
| 74 | $props = $post->get_properties(); |
| 75 | |
| 76 | foreach ( $props as $prop => $value ) { |
| 77 | if ( metadata_exists( 'post', $post->id(), '_' . $prop ) ) { |
| 78 | continue; |
| 79 | } |
| 80 | |
| 81 | update_post_meta( $post->id(), '_' . $prop, $value ); |
| 82 | delete_post_meta( $post->id(), $prop ); |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 |