abstracts
4 years ago
admin
4 years ago
elementor
4 years ago
export
4 years ago
fields
4 years ago
interfaces
8 years ago
libraries
7 years ago
log-handlers
4 years ago
shortcodes
4 years ago
templates
5 years ago
class-everest-forms.php
4 years ago
class-evf-ajax.php
4 years ago
class-evf-autoloader.php
7 years ago
class-evf-background-updater.php
7 years ago
class-evf-cache-helper.php
6 years ago
class-evf-deprecated-action-hooks.php
6 years ago
class-evf-deprecated-filter-hooks.php
5 years ago
class-evf-emails.php
5 years ago
class-evf-fields.php
6 years ago
class-evf-form-block.php
4 years ago
class-evf-form-handler.php
4 years ago
class-evf-form-task.php
4 years ago
class-evf-forms-features.php
4 years ago
class-evf-frontend-scripts.php
4 years ago
class-evf-install.php
5 years ago
class-evf-integrations.php
7 years ago
class-evf-log-levels.php
8 years ago
class-evf-logger.php
5 years ago
class-evf-post-types.php
5 years ago
class-evf-privacy.php
6 years ago
class-evf-session-handler.php
7 years ago
class-evf-shortcodes.php
4 years ago
class-evf-smart-tags.php
4 years ago
class-evf-template-loader.php
4 years ago
class-evf-validation.php
6 years ago
evf-conditional-functions.php
6 years ago
evf-core-functions.php
4 years ago
evf-deprecated-functions.php
6 years ago
evf-entry-functions.php
4 years ago
evf-formatting-functions.php
4 years ago
evf-notice-functions.php
4 years ago
evf-template-functions.php
4 years ago
evf-template-hooks.php
7 years ago
evf-update-functions.php
5 years ago
evf-update-functions.php
384 lines
| 1 | <?php |
| 2 | /** |
| 3 | * EverestForms Updates |
| 4 | * |
| 5 | * Functions for updating data, used by the background updater. |
| 6 | * |
| 7 | * @package EverestForms\Functions |
| 8 | * @since 1.0.0 |
| 9 | */ |
| 10 | |
| 11 | defined( 'ABSPATH' ) || exit; |
| 12 | |
| 13 | /** |
| 14 | * Update DB Version. |
| 15 | */ |
| 16 | function evf_update_100_db_version() { |
| 17 | EVF_Install::update_db_version( '1.0.0' ); |
| 18 | } |
| 19 | |
| 20 | /** |
| 21 | * Update DB Version. |
| 22 | */ |
| 23 | function evf_update_101_db_version() { |
| 24 | EVF_Install::update_db_version( '1.0.1' ); |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * Update DB Version. |
| 29 | */ |
| 30 | function evf_update_102_db_version() { |
| 31 | EVF_Install::update_db_version( '1.0.2' ); |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Update DB Version. |
| 36 | */ |
| 37 | function evf_update_103_db_version() { |
| 38 | EVF_Install::update_db_version( '1.0.3' ); |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Update all forms for meta-key. |
| 43 | */ |
| 44 | function evf_update_110_update_forms() { |
| 45 | $forms = evf_get_all_forms(); |
| 46 | |
| 47 | foreach ( $forms as $form_id => $form ) { |
| 48 | $form_obj = evf()->form->get( $form_id ); |
| 49 | $form_data = ! empty( $form_obj->post_content ) ? evf_decode( $form_obj->post_content ) : ''; |
| 50 | |
| 51 | if ( ! empty( $form_data['form_fields'] ) ) { |
| 52 | foreach ( $form_data['form_fields'] as &$field ) { |
| 53 | if ( ! isset( $field['meta-key'] ) ) { |
| 54 | $field['meta-key'] = evf_get_meta_key_field_option( $field ); |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | // Update form data. |
| 60 | evf()->form->update( $form_id, $form_data ); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Update DB Version. |
| 66 | */ |
| 67 | function evf_update_110_db_version() { |
| 68 | EVF_Install::update_db_version( '1.1.0' ); |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Delete global email related options. |
| 73 | */ |
| 74 | function evf_update_116_delete_options() { |
| 75 | $delete_options = array( |
| 76 | 'evf_to_email', |
| 77 | 'evf_from_name', |
| 78 | 'evf_from_address', |
| 79 | 'evf_email_subject', |
| 80 | 'evf_email_message', |
| 81 | 'everest_forms_disable_form_entries', |
| 82 | 'everest_forms_form_submit_button_label', |
| 83 | 'everest_forms_successful_form_submission_message', |
| 84 | ); |
| 85 | |
| 86 | foreach ( $delete_options as $delete_option ) { |
| 87 | delete_option( $delete_option ); |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Update DB Version. |
| 93 | */ |
| 94 | function evf_update_116_db_version() { |
| 95 | EVF_Install::update_db_version( '1.1.6' ); |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * Update settings option to use new renamed option for 1.2.0. |
| 100 | */ |
| 101 | function evf_update_120_db_rename_options() { |
| 102 | $rename_options = array( |
| 103 | 'evf_email_template' => 'everest_forms_email_template', |
| 104 | 'evf_recaptcha_site_key' => 'everest_forms_recaptcha_site_key', |
| 105 | 'evf_recaptcha_site_secret' => 'everest_forms_recaptcha_site_secret', |
| 106 | 'evf_required_validation' => 'everest_forms_required_validation', |
| 107 | 'evf_url_validation' => 'everest_forms_url_validation', |
| 108 | 'evf_email_validation' => 'everest_forms_email_validation', |
| 109 | 'evf_number_validation' => 'everest_forms_number_validation', |
| 110 | 'evf_recaptcha_validation' => 'everest_forms_recaptcha_validation', |
| 111 | 'evf_default_form_page_id' => 'everest_forms_default_form_page_id', |
| 112 | ); |
| 113 | |
| 114 | foreach ( $rename_options as $old_option => $new_option ) { |
| 115 | $raw_old_option = get_option( $old_option ); |
| 116 | |
| 117 | if ( ! empty( $raw_old_option ) ) { |
| 118 | update_option( $new_option, $raw_old_option ); |
| 119 | delete_option( $old_option ); |
| 120 | } |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * Update email settings adding connection data. |
| 126 | */ |
| 127 | function evf_update_140_db_multiple_email() { |
| 128 | $forms = evf()->form->get_multiple( array( 'order' => 'DESC' ) ); |
| 129 | |
| 130 | // Loop through each forms. |
| 131 | foreach ( $forms as $form ) { |
| 132 | $form_id = isset( $form->ID ) ? $form->ID : '0'; |
| 133 | $form_data = ! empty( $form->post_content ) ? evf_decode( $form->post_content ) : ''; |
| 134 | |
| 135 | if ( ! empty( $form_data['settings'] ) ) { |
| 136 | $email = (array) $form_data['settings']['email']; |
| 137 | |
| 138 | // New email conn. |
| 139 | $new_email = array(); |
| 140 | $new_email['connection_name'] = esc_html__( 'Admin Notification', 'everest-forms' ); |
| 141 | $new_email = array_merge( $new_email, $email ); |
| 142 | |
| 143 | // Unset previous email data structure. |
| 144 | $email_settings = array( 'evf_send_confirmation_email', 'evf_user_to_email', 'evf_user_email_subject', 'evf_user_email_message', 'attach_pdf_to_user_email' ); |
| 145 | foreach ( $email_settings as $email_setting ) { |
| 146 | unset( $email_setting ); |
| 147 | } |
| 148 | |
| 149 | // Maintain the multiple-email connections data structure. |
| 150 | if ( ! isset( $form_data['settings']['email']['connection_1'] ) ) { |
| 151 | $unique_connection_id = sprintf( 'connection_%s', uniqid() ); |
| 152 | $form_data['settings']['email'] = array( 'connection_1' => $new_email ); |
| 153 | |
| 154 | if ( isset( $email['evf_send_confirmation_email'] ) && '1' === $email['evf_send_confirmation_email'] ) { |
| 155 | $form_data['settings']['email'][ $unique_connection_id ] = array( |
| 156 | 'connection_name' => esc_html__( 'User Notification', 'everest-forms' ), |
| 157 | 'evf_to_email' => '{field_id="' . $email['evf_user_to_email'] . '"}', |
| 158 | 'evf_from_name' => $email['evf_from_name'], |
| 159 | 'evf_from_email' => $email['evf_from_email'], |
| 160 | 'evf_reply_to' => $email['evf_reply_to'], |
| 161 | 'evf_email_subject' => $email['evf_user_email_subject'], |
| 162 | 'evf_email_message' => $email['evf_user_email_message'], |
| 163 | ); |
| 164 | } |
| 165 | |
| 166 | if ( isset( $email['attach_pdf_to_user_email'] ) && '1' === $email['attach_pdf_to_user_email'] ) { |
| 167 | $form_data['settings']['email'][ $unique_connection_id ]['attach_pdf_to_admin_email'] = '1'; |
| 168 | } |
| 169 | |
| 170 | if ( isset( $email['conditional_logic_status'] ) ) { |
| 171 | $form_data['settings']['email'][ $unique_connection_id ]['conditional_logic_status'] = $email['conditional_logic_status']; |
| 172 | $form_data['settings']['email'][ $unique_connection_id ]['conditional_option'] = $email['conditional_option']; |
| 173 | $form_data['settings']['email'][ $unique_connection_id ]['conditionals'] = array(); |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | // Update form data. |
| 178 | evf()->form->update( $form_id, $form_data ); |
| 179 | } |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | /** |
| 184 | * Update DB Version. |
| 185 | */ |
| 186 | function evf_update_120_db_version() { |
| 187 | EVF_Install::update_db_version( '1.2.0' ); |
| 188 | } |
| 189 | |
| 190 | /** |
| 191 | * Update DB Version. |
| 192 | */ |
| 193 | function evf_update_130_db_version() { |
| 194 | EVF_Install::update_db_version( '1.3.0' ); |
| 195 | } |
| 196 | |
| 197 | /** |
| 198 | * Update DB Version. |
| 199 | */ |
| 200 | function evf_update_140_db_version() { |
| 201 | EVF_Install::update_db_version( '1.4.0' ); |
| 202 | } |
| 203 | |
| 204 | /** |
| 205 | * Delete global reCAPTCHA related options. |
| 206 | */ |
| 207 | function evf_update_144_delete_options() { |
| 208 | delete_option( 'everest_forms_recaptcha_validation' ); |
| 209 | } |
| 210 | |
| 211 | /** |
| 212 | * Update DB Version. |
| 213 | */ |
| 214 | function evf_update_144_db_version() { |
| 215 | EVF_Install::update_db_version( '1.4.4' ); |
| 216 | } |
| 217 | |
| 218 | /** |
| 219 | * Update settings option to use new renamed option for 1.4.9. |
| 220 | */ |
| 221 | function evf_update_149_db_rename_options() { |
| 222 | $rename_options = array( |
| 223 | 'everest_forms_recaptcha_site_key' => 'everest_forms_recaptcha_v2_site_key', |
| 224 | 'everest_forms_recaptcha_site_secret' => 'everest_forms_recaptcha_v2_secret_key', |
| 225 | ); |
| 226 | |
| 227 | foreach ( $rename_options as $old_option => $new_option ) { |
| 228 | $raw_old_option = get_option( $old_option ); |
| 229 | |
| 230 | if ( ! empty( $raw_old_option ) ) { |
| 231 | update_option( $new_option, $raw_old_option ); |
| 232 | delete_option( $old_option ); |
| 233 | } |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | /** |
| 238 | * Remove payment option field from all forms. |
| 239 | */ |
| 240 | function evf_update_149_no_payment_options() { |
| 241 | $forms = evf_get_all_forms(); |
| 242 | |
| 243 | // Loop through each forms. |
| 244 | foreach ( $forms as $form_id => $form ) { |
| 245 | $form_obj = evf()->form->get( $form_id ); |
| 246 | $form_data = ! empty( $form_obj->post_content ) ? evf_decode( $form_obj->post_content ) : ''; |
| 247 | |
| 248 | if ( ! empty( $form_data['form_fields'] ) ) { |
| 249 | foreach ( $form_data['form_fields'] as $field_id => &$field ) { |
| 250 | if ( isset( $field['type'] ) && 'payment-charge-options' === $field['type'] ) { |
| 251 | unset( $form_data['form_fields'][ $field_id ] ); |
| 252 | } |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | // Update form data. |
| 257 | evf()->form->update( $form_id, $form_data ); |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | /** |
| 262 | * Update DB Version. |
| 263 | */ |
| 264 | function evf_update_149_db_version() { |
| 265 | EVF_Install::update_db_version( '1.4.9' ); |
| 266 | } |
| 267 | |
| 268 | /** |
| 269 | * Update date field type for all forms. |
| 270 | */ |
| 271 | function evf_update_150_field_datetime_type() { |
| 272 | $forms = evf()->form->get_multiple( array( 'order' => 'DESC' ) ); |
| 273 | |
| 274 | // Loop through each forms. |
| 275 | foreach ( $forms as $form ) { |
| 276 | $form_id = isset( $form->ID ) ? $form->ID : '0'; |
| 277 | $form_data = ! empty( $form->post_content ) ? evf_decode( $form->post_content ) : ''; |
| 278 | |
| 279 | if ( ! empty( $form_data['form_fields'] ) ) { |
| 280 | foreach ( $form_data['form_fields'] as &$field ) { |
| 281 | if ( isset( $field['type'] ) && 'date' === $field['type'] ) { |
| 282 | $field['type'] = 'date-time'; |
| 283 | } |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | // Update form data. |
| 288 | evf()->form->update( $form_id, $form_data ); |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | /** |
| 293 | * Update DB Version. |
| 294 | */ |
| 295 | function evf_update_150_db_version() { |
| 296 | EVF_Install::update_db_version( '1.5.0' ); |
| 297 | } |
| 298 | |
| 299 | /** |
| 300 | * Update DB Version. |
| 301 | */ |
| 302 | function evf_update_160_db_version() { |
| 303 | EVF_Install::update_db_version( '1.6.0' ); |
| 304 | } |
| 305 | |
| 306 | /** |
| 307 | * Update core capabilities. |
| 308 | */ |
| 309 | function evf_update_175_remove_capabilities() { |
| 310 | global $wp_roles; |
| 311 | |
| 312 | if ( ! class_exists( 'WP_Roles' ) ) { |
| 313 | return; |
| 314 | } |
| 315 | |
| 316 | if ( ! isset( $wp_roles ) ) { |
| 317 | $wp_roles = new WP_Roles(); // @codingStandardsIgnoreLine |
| 318 | } |
| 319 | |
| 320 | $capability_types = array( 'everest_form' ); |
| 321 | |
| 322 | foreach ( $capability_types as $capability_type ) { |
| 323 | $capabilities[ $capability_type ] = array( |
| 324 | // Post type. |
| 325 | "edit_{$capability_type}", |
| 326 | "read_{$capability_type}", |
| 327 | "delete_{$capability_type}", |
| 328 | "edit_{$capability_type}s", |
| 329 | "edit_others_{$capability_type}s", |
| 330 | "publish_{$capability_type}s", |
| 331 | "read_private_{$capability_type}s", |
| 332 | "delete_{$capability_type}s", |
| 333 | "delete_private_{$capability_type}s", |
| 334 | "delete_published_{$capability_type}s", |
| 335 | "delete_others_{$capability_type}s", |
| 336 | "edit_private_{$capability_type}s", |
| 337 | "edit_published_{$capability_type}s", |
| 338 | |
| 339 | // Terms. |
| 340 | "manage_{$capability_type}_terms", |
| 341 | "edit_{$capability_type}_terms", |
| 342 | "delete_{$capability_type}_terms", |
| 343 | "assign_{$capability_type}_terms", |
| 344 | ); |
| 345 | } |
| 346 | |
| 347 | // Remove unused core capabilities. |
| 348 | foreach ( $capabilities as $cap_group ) { |
| 349 | foreach ( $cap_group as $cap ) { |
| 350 | $wp_roles->remove_cap( 'administrator', $cap ); |
| 351 | } |
| 352 | } |
| 353 | } |
| 354 | |
| 355 | /** |
| 356 | * Restore draft forms to publish. |
| 357 | */ |
| 358 | function evf_update_175_restore_draft_forms() { |
| 359 | $form_ids = get_posts( |
| 360 | array( |
| 361 | 'post_type' => 'everest_form', |
| 362 | 'post_status' => 'draft', |
| 363 | 'fields' => 'ids', |
| 364 | 'numberposts' => - 1, |
| 365 | ) |
| 366 | ); |
| 367 | |
| 368 | foreach ( $form_ids as $form_id ) { |
| 369 | wp_update_post( |
| 370 | array( |
| 371 | 'ID' => $form_id, |
| 372 | 'post_status' => 'publish', |
| 373 | ) |
| 374 | ); |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | /** |
| 379 | * Update DB Version. |
| 380 | */ |
| 381 | function evf_update_175_db_version() { |
| 382 | EVF_Install::update_db_version( '1.7.5' ); |
| 383 | } |
| 384 |