block-editor
1 year ago
config-validator
1 year ago
css
2 years ago
js
1 year ago
swv
1 year ago
capabilities.php
7 years ago
contact-form-functions.php
1 year ago
contact-form-template.php
1 year ago
contact-form.php
1 year ago
controller.php
1 year ago
file.php
1 year ago
form-tag.php
1 year ago
form-tags-manager.php
1 year ago
formatting.php
1 year ago
functions.php
1 year ago
html-formatter.php
1 year ago
integration.php
1 year ago
l10n.php
1 year ago
mail-tag.php
2 years ago
mail.php
1 year ago
pipe.php
1 year ago
pocket-holder.php
3 years ago
rest-api.php
1 year ago
shortcodes.php
1 year ago
special-mail-tags.php
1 year ago
submission.php
1 year ago
upgrade.php
2 years ago
validation-functions.php
1 year ago
validation.php
1 year ago
upgrade.php
134 lines
| 1 | <?php |
| 2 | |
| 3 | add_action( 'wpcf7_upgrade', 'wpcf7_upgrade_58', 10, 2 ); |
| 4 | |
| 5 | /** |
| 6 | * Runs functions necessary when upgrading from old plugin versions before 5.8. |
| 7 | * |
| 8 | * @since 5.8.0 New `_config_validation` post meta is introduced. |
| 9 | */ |
| 10 | function wpcf7_upgrade_58( $new_ver, $old_ver ) { |
| 11 | if ( ! version_compare( $old_ver, '5.8-dev', '<' ) ) { |
| 12 | return; |
| 13 | } |
| 14 | |
| 15 | $posts = WPCF7_ContactForm::find( array( |
| 16 | 'post_status' => 'any', |
| 17 | 'posts_per_page' => -1, |
| 18 | ) ); |
| 19 | |
| 20 | foreach ( $posts as $post ) { |
| 21 | $post_id = $post->id(); |
| 22 | |
| 23 | // Delete the old post meta for config-validation results. |
| 24 | delete_post_meta( $post_id, '_config_errors' ); |
| 25 | |
| 26 | // Add the contact form hash. |
| 27 | add_post_meta( $post_id, '_hash', |
| 28 | wpcf7_generate_contact_form_hash( $post_id ), |
| 29 | true // Unique |
| 30 | ); |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | |
| 35 | add_action( 'wpcf7_upgrade', 'wpcf7_convert_to_cpt', 10, 2 ); |
| 36 | |
| 37 | /** |
| 38 | * Converts old data in the dedicated database table to custom posts. |
| 39 | * |
| 40 | * @since 3.0.0 `wpcf7_contact_form` CPT is introduced. |
| 41 | */ |
| 42 | function wpcf7_convert_to_cpt( $new_ver, $old_ver ) { |
| 43 | global $wpdb; |
| 44 | |
| 45 | if ( ! version_compare( $old_ver, '3.0-dev', '<' ) ) { |
| 46 | return; |
| 47 | } |
| 48 | |
| 49 | $old_rows = array(); |
| 50 | |
| 51 | $table_name = $wpdb->prefix . "contact_form_7"; |
| 52 | |
| 53 | if ( $wpdb->get_var( "SHOW TABLES LIKE '$table_name'" ) ) { |
| 54 | $old_rows = $wpdb->get_results( "SELECT * FROM $table_name" ); |
| 55 | } elseif ( $opt = get_option( 'wpcf7' ) |
| 56 | and ! empty( $opt['contact_forms'] ) ) { |
| 57 | foreach ( (array) $opt['contact_forms'] as $key => $value ) { |
| 58 | $old_rows[] = (object) array_merge( |
| 59 | $value, |
| 60 | array( 'cf7_unit_id' => $key ) |
| 61 | ); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | foreach ( (array) $old_rows as $row ) { |
| 66 | $q = "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_old_cf7_unit_id'" |
| 67 | . $wpdb->prepare( " AND meta_value = %d", $row->cf7_unit_id ); |
| 68 | |
| 69 | if ( $wpdb->get_var( $q ) ) { |
| 70 | continue; |
| 71 | } |
| 72 | |
| 73 | $postarr = array( |
| 74 | 'post_type' => 'wpcf7_contact_form', |
| 75 | 'post_status' => 'publish', |
| 76 | 'post_title' => maybe_unserialize( $row->title ), |
| 77 | ); |
| 78 | |
| 79 | $post_id = wp_insert_post( $postarr ); |
| 80 | |
| 81 | if ( $post_id ) { |
| 82 | update_post_meta( $post_id, '_old_cf7_unit_id', $row->cf7_unit_id ); |
| 83 | |
| 84 | $metas = array( |
| 85 | 'form', |
| 86 | 'mail', |
| 87 | 'mail_2', |
| 88 | 'messages', |
| 89 | 'additional_settings', |
| 90 | ); |
| 91 | |
| 92 | foreach ( $metas as $meta ) { |
| 93 | update_post_meta( $post_id, '_' . $meta, |
| 94 | wpcf7_normalize_newline_deep( maybe_unserialize( $row->{$meta} ) ) |
| 95 | ); |
| 96 | } |
| 97 | } |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | |
| 102 | add_action( 'wpcf7_upgrade', 'wpcf7_prepend_underscore', 10, 2 ); |
| 103 | |
| 104 | /** |
| 105 | * Prepends an underscore to post meta keys. |
| 106 | */ |
| 107 | function wpcf7_prepend_underscore( $new_ver, $old_ver ) { |
| 108 | if ( version_compare( $old_ver, '3.0-dev', '<' ) ) { |
| 109 | return; |
| 110 | } |
| 111 | |
| 112 | if ( ! version_compare( $old_ver, '3.3-dev', '<' ) ) { |
| 113 | return; |
| 114 | } |
| 115 | |
| 116 | $posts = WPCF7_ContactForm::find( array( |
| 117 | 'post_status' => 'any', |
| 118 | 'posts_per_page' => -1, |
| 119 | ) ); |
| 120 | |
| 121 | foreach ( $posts as $post ) { |
| 122 | $props = $post->get_properties(); |
| 123 | |
| 124 | foreach ( $props as $prop => $value ) { |
| 125 | if ( metadata_exists( 'post', $post->id(), '_' . $prop ) ) { |
| 126 | continue; |
| 127 | } |
| 128 | |
| 129 | update_post_meta( $post->id(), '_' . $prop, $value ); |
| 130 | delete_post_meta( $post->id(), $prop ); |
| 131 | } |
| 132 | } |
| 133 | } |
| 134 |