block-editor
1 year ago
config-validator
11 months ago
css
3 weeks ago
js
1 year ago
swv
10 months ago
capabilities.php
7 years ago
contact-form-functions.php
11 months ago
contact-form-template.php
11 months ago
contact-form.php
11 months ago
controller.php
11 months ago
file.php
10 months ago
filesystem.php
11 months ago
form-tag.php
7 months ago
form-tags-manager.php
11 months ago
formatting.php
11 months ago
functions.php
10 months ago
html-formatter.php
10 months ago
integration.php
11 months ago
l10n.php
11 months ago
mail-tag.php
11 months ago
mail.php
3 months ago
pipe.php
11 months ago
pocket-holder.php
3 years ago
rest-api.php
11 months ago
shortcodes.php
11 months ago
special-mail-tags.php
10 months ago
submission.php
10 months ago
upgrade.php
11 months ago
validation-functions.php
11 months ago
validation.php
11 months ago
upgrade.php
146 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_exists = $wpdb->get_var( $wpdb->prepare( |
| 52 | "SHOW TABLES LIKE %s", |
| 53 | $wpdb->prefix . 'contact_form_7' |
| 54 | ) ); |
| 55 | |
| 56 | if ( $table_exists ) { |
| 57 | $old_rows = $wpdb->get_results( $wpdb->prepare( |
| 58 | "SELECT * FROM %i", |
| 59 | $wpdb->prefix . 'contact_form_7' |
| 60 | ) ); |
| 61 | } elseif ( |
| 62 | $opt = get_option( 'wpcf7' ) and |
| 63 | ! empty( $opt['contact_forms'] ) |
| 64 | ) { |
| 65 | foreach ( (array) $opt['contact_forms'] as $key => $value ) { |
| 66 | $old_rows[] = (object) array_merge( |
| 67 | $value, |
| 68 | array( 'cf7_unit_id' => $key ) |
| 69 | ); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | foreach ( (array) $old_rows as $row ) { |
| 74 | $var = $wpdb->get_var( $wpdb->prepare( |
| 75 | "SELECT post_id FROM %i WHERE meta_key = %s AND meta_value = %d", |
| 76 | $wpdb->postmeta, |
| 77 | '_old_cf7_unit_id', |
| 78 | $row->cf7_unit_id |
| 79 | ) ); |
| 80 | |
| 81 | if ( $var ) { |
| 82 | continue; |
| 83 | } |
| 84 | |
| 85 | $postarr = array( |
| 86 | 'post_type' => 'wpcf7_contact_form', |
| 87 | 'post_status' => 'publish', |
| 88 | 'post_title' => maybe_unserialize( $row->title ), |
| 89 | ); |
| 90 | |
| 91 | $post_id = wp_insert_post( $postarr ); |
| 92 | |
| 93 | if ( $post_id ) { |
| 94 | update_post_meta( $post_id, '_old_cf7_unit_id', $row->cf7_unit_id ); |
| 95 | |
| 96 | $metas = array( |
| 97 | 'form', |
| 98 | 'mail', |
| 99 | 'mail_2', |
| 100 | 'messages', |
| 101 | 'additional_settings', |
| 102 | ); |
| 103 | |
| 104 | foreach ( $metas as $meta ) { |
| 105 | update_post_meta( $post_id, '_' . $meta, |
| 106 | wpcf7_normalize_newline_deep( maybe_unserialize( $row->{$meta} ) ) |
| 107 | ); |
| 108 | } |
| 109 | } |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | |
| 114 | add_action( 'wpcf7_upgrade', 'wpcf7_prepend_underscore', 10, 2 ); |
| 115 | |
| 116 | /** |
| 117 | * Prepends an underscore to post meta keys. |
| 118 | */ |
| 119 | function wpcf7_prepend_underscore( $new_ver, $old_ver ) { |
| 120 | if ( version_compare( $old_ver, '3.0-dev', '<' ) ) { |
| 121 | return; |
| 122 | } |
| 123 | |
| 124 | if ( ! version_compare( $old_ver, '3.3-dev', '<' ) ) { |
| 125 | return; |
| 126 | } |
| 127 | |
| 128 | $posts = WPCF7_ContactForm::find( array( |
| 129 | 'post_status' => 'any', |
| 130 | 'posts_per_page' => -1, |
| 131 | ) ); |
| 132 | |
| 133 | foreach ( $posts as $post ) { |
| 134 | $props = $post->get_properties(); |
| 135 | |
| 136 | foreach ( $props as $prop => $value ) { |
| 137 | if ( metadata_exists( 'post', $post->id(), '_' . $prop ) ) { |
| 138 | continue; |
| 139 | } |
| 140 | |
| 141 | update_post_meta( $post->id(), '_' . $prop, $value ); |
| 142 | delete_post_meta( $post->id(), $prop ); |
| 143 | } |
| 144 | } |
| 145 | } |
| 146 |