| @@ -450,9 +450,8 @@ | ||
| 450 | 450 | /** |
| 451 | 451 | * Renders the Give Deactivation Survey Form. |
| 452 | 452 | * Note: only for internal use |
| 453 | 453 | * |
| 454 | - * @since 4.10.0 Updated the icon path to the new build directory. | |
| 455 | 454 | * @since 2.2 |
| 456 | 455 | */ |
| 457 | 456 | function give_deactivation_popup() { |
| 458 | 457 | // Bailout. |
| @@ -466,9 +465,9 @@ | ||
| 466 | 465 | ob_start(); |
| 467 | 466 | ?> |
| 468 | 467 | |
| 469 | 468 | <h2 id="deactivation-survey-title"> |
| 470 | - <img src="<?php echo esc_url( GIVE_PLUGIN_URL ); ?>/build/assets/dist/images/give-icon-full-circle.svg"> | |
| 469 | + <img src="<?php echo esc_url( GIVE_PLUGIN_URL ); ?>/assets/dist/images/give-icon-full-circle.svg"> | |
| 471 | 470 | <span><?php esc_html_e( 'GiveWP Deactivation', 'give' ); ?></span> |
| 472 | 471 | </h2> |
| 473 | 472 | <form class="deactivation-survey-form" method="POST"> |
| 474 | 473 | <p><?php esc_html_e( 'If you have a moment, please let us know why you are deactivating Give. All submissions are anonymous and we only use this feedback to improve this plugin.', 'give' ); ?></p> |
| @@ -570,8 +569,14 @@ | ||
| 570 | 569 | <?php esc_html_e( 'By default the custom roles, GiveWP options, and database entries are not deleted when you deactivate Give. If you are deleting GiveWP completely from your website and want those items removed as well check this option. Note: This will permanently delete all GiveWP data from your database.', 'give' ); ?> |
| 571 | 570 | </section> |
| 572 | 571 | </p> |
| 573 | 572 | </div> |
| 573 | + <?php | |
| 574 | + $current_user = wp_get_current_user(); | |
| 575 | + $current_user_email = $current_user->user_email; | |
| 576 | + ?> | |
| 577 | + <input type="hidden" name="current-user-email" value="<?php echo $current_user_email; ?>"> | |
| 578 | + <input type="hidden" name="current-site-url" value="<?php echo esc_url( get_bloginfo( 'url' ) ); ?>"> | |
| 574 | 579 | <input type="hidden" name="give-export-class" value="Give_Tools_Reset_Stats"> |
| 575 | 580 | <?php wp_nonce_field( 'give_ajax_export', 'give_ajax_export' ); ?> |
| 576 | 581 | </form> |
| 577 | 582 | |
| @@ -606,28 +611,44 @@ | ||
| 606 | 611 | |
| 607 | 612 | // Get the reason if any radio button has an optional text field. |
| 608 | 613 | $user_reason = isset( $form_data['user-reason'] ) ? $form_data['user-reason'] : ''; |
| 609 | 614 | |
| 615 | + // Get the email of the user who deactivated the plugin. | |
| 616 | + $user_email = isset( $form_data['current-user-email'] ) ? $form_data['current-user-email'] : ''; | |
| 617 | + | |
| 618 | + // Get the URL of the website on which Give plugin is being deactivated. | |
| 619 | + $site_url = isset( $form_data['current-site-url'] ) ? $form_data['current-site-url'] : ''; | |
| 620 | + | |
| 610 | 621 | // Get the value of the checkbox for deleting Give's data. |
| 611 | 622 | $delete_data = isset( $form_data['confirm_reset_store'] ) ? $form_data['confirm_reset_store'] : ''; |
| 612 | 623 | |
| 613 | - // Send data to survey server. It doesn't matter if it fails. | |
| 614 | - wp_remote_post( | |
| 615 | - 'http://survey.givewp.com/wp-json/give/v2/survey/', | |
| 616 | - [ | |
| 617 | - 'body' => [ | |
| 618 | - 'radio_value' => $radio_value, | |
| 619 | - 'user_reason' => $user_reason, | |
| 620 | - ], | |
| 621 | - 'timeout' => 0.1 | |
| 622 | - ] | |
| 623 | - ); | |
| 624 | + /** | |
| 625 | + * Make a POST request to the endpoint to send the survey data. | |
| 626 | + */ | |
| 627 | + $response = wp_remote_post( | |
| 628 | + 'http://survey.givewp.com/wp-json/give/v2/survey/', | |
| 629 | + [ | |
| 630 | + 'body' => [ | |
| 631 | + 'radio_value' => $radio_value, | |
| 632 | + 'user_reason' => $user_reason, | |
| 633 | + 'current_user_email' => $user_email, | |
| 634 | + 'site_url' => $site_url, | |
| 635 | + ], | |
| 636 | + ] | |
| 637 | + ); | |
| 624 | 638 | |
| 625 | - if ( '1' === $delete_data ) { | |
| 626 | - give_update_option( 'uninstall_on_delete', 'enabled' ); | |
| 627 | - wp_send_json_success( [ 'delete_data' => true ] ); | |
| 628 | - } | |
| 639 | + // Check if the data is sent and stored correctly. | |
| 640 | + $response = wp_remote_retrieve_body( $response ); | |
| 629 | 641 | |
| 630 | - wp_send_json_success( [ 'delete_data' => false ] ); | |
| 642 | + if ( 'true' === $response ) { | |
| 643 | + if ( '1' === $delete_data ) { | |
| 644 | + give_update_option( 'uninstall_on_delete', 'enabled' ); | |
| 645 | + wp_send_json_success( [ 'delete_data' => true ] ); | |
| 646 | + } | |
| 647 | + | |
| 648 | + wp_send_json_success( [ 'delete_data' => false ] ); | |
| 649 | + } | |
| 650 | + | |
| 651 | + wp_send_json_error(); | |
| 631 | 652 | } |
| 632 | 653 | |
| 633 | 654 | add_action( 'wp_ajax_deactivation_form_submit', 'give_deactivation_form_submit' ); |