diff --git a/assets/css/um-account.css b/assets/css/um-account.css index 89b84b1a..9a922044 100644 --- a/assets/css/um-account.css +++ b/assets/css/um-account.css @@ -205,4 +205,30 @@ color: #444; font-weight: bold; text-decoration: none !important; +} + +.um-field-export_data .um-field-error { + display: none; +} + +.um-field-export_data .um-field-area-response { + display: none; + line-height: 1.5; + padding: 10px 0; +} + +.um-request-button { + display: inline-block; + background-color: #3ba1da; + border-radius: 5px; + color: #fff; + margin: 10px 0 0; + padding: 5px 10px; + text-decoration: none; +} + +.um-request-button:hover { + background-color: #44b0ec; + color: #fff; + text-decoration: none; } \ No newline at end of file diff --git a/assets/js/um-account.js b/assets/js/um-account.js index ba033531..a4587bb2 100644 --- a/assets/js/um-account.js +++ b/assets/js/um-account.js @@ -64,4 +64,35 @@ jQuery(document).ready(function() { return false; }); + + + jQuery(document.body).on( 'click', '.um-request-button', function(e) { + e.preventDefault(); + + var request_action = jQuery(this).data('action'); + var password = jQuery('#'+request_action).val(); + jQuery('.um-field-area-response.'+request_action).hide(); + + if( password === '' ){ + jQuery('.um-field-error.'+request_action).show(); + } else { + jQuery('.um-field-error.'+request_action).hide(); + var request = { + request_action: request_action, + password: password, + nonce: um_scripts.nonce + }; + wp.ajax.send('um_request_user_data', { + data: request, + success: function (data) { + jQuery('.um-field-area-response.'+request_action).text(data.answer).show(); + }, + error: function (data) { + console.log(data); + } + }); + } + + }); + }); \ No newline at end of file diff --git a/includes/core/um-actions-account.php b/includes/core/um-actions-account.php index dc6d65c1..2389ac0b 100644 --- a/includes/core/um-actions-account.php +++ b/includes/core/um-actions-account.php @@ -463,4 +463,100 @@ add_action( 'um_after_user_account_updated', 'um_account_updated_notification', function um_disable_native_email_notificatiion( $changed, $user_id ) { add_filter( 'send_email_change_email', '__return_false' ); } -add_action( 'um_account_pre_update_profile', 'um_disable_native_email_notificatiion', 10, 2 ); \ No newline at end of file +add_action( 'um_account_pre_update_profile', 'um_disable_native_email_notificatiion', 10, 2 ); + + +/** + * Add export and erase user's data in privacy tab + * + * @param $args + */ +add_action( 'um_after_account_privacy', 'um_after_account_privacy' ); +function um_after_account_privacy( $args ) { + ?> + +
+
+ + + + +
+
+ +
+ +
+ +
+
+
+ + + +
+ +
+
+ + + + +
+
+ + + + +
+ + check_ajax_nonce(); + + $user_id = get_current_user_id(); + $password = $_POST['password']; + $user = get_userdata( $user_id ); + $hash = $user->data->user_pass; + + if ( wp_check_password( $password, $hash ) && isset( $_POST['request_action'] ) ) { + + if ( $_POST['request_action'] == 'um-export-data' ) { + $request_id = wp_create_user_request( $user->data->user_email, 'export_personal_data' ); + } elseif ( $_POST['request_action'] == 'um-erase-data' ) { + $request_id = wp_create_user_request( $user->data->user_email, 'remove_personal_data' ); + } + + if ( is_wp_error( $request_id ) ) { + $answer = $request_id->get_error_message(); + } else { + wp_send_user_request( $request_id ); + $answer = esc_html__( 'A confirmation email has been sent to your email. Click the link within the email to confirm your export request.', 'ultimate-member' ); + } + + } else { + + $answer = esc_html__( 'The password you entered is incorrect.', 'ultimate-member' ); + + } + + wp_send_json_success( array( 'answer' => esc_html( $answer ) ) ); +} +add_action( 'wp_ajax_nopriv_um_request_user_data', 'um_request_user_data' ); +add_action( 'wp_ajax_um_request_user_data', 'um_request_user_data' ); \ No newline at end of file