| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 3 |
|
| 4 |
/* handle field output */ |
| 5 |
function wppb_gdpr_delete_handler( $output, $form_location, $field, $user_id, $field_check_errors, $request_data ){ |
| 6 |
if ( $field['field'] == 'GDPR Delete Button' ){ |
| 7 |
if ( $form_location === 'edit_profile' ){ |
| 8 |
$item_title = apply_filters( 'wppb_'.$form_location.'_gdpr_delete_custom_field_'.$field['id'].'_item_title', wppb_icl_t( 'plugin profile-builder-pro', 'custom_field_'.$field['id'].'_title_translation', $field['field-title'], true ) ); |
| 9 |
$item_description = wppb_icl_t( 'plugin profile-builder-pro', 'custom_field_'.$field['id'].'_description_translation', $field['description'], true ); |
| 10 |
|
| 11 |
$edited_user_id = get_current_user_id(); |
| 12 |
if( ( !is_multisite() && current_user_can( 'edit_users' ) ) || ( is_multisite() && current_user_can( 'manage_network' ) ) ) { |
| 13 |
if( isset( $_GET['edit_user'] ) && ! empty( $_GET['edit_user'] ) ){ |
| 14 |
$edited_user_id = absint( $_GET['edit_user'] ); |
| 15 |
} |
| 16 |
} |
| 17 |
|
| 18 |
$output = ' |
| 19 |
<label for="wppb-delete-account">'. wp_kses_post( $item_title ) .'</label> |
| 20 |
<input class="wppb-delete-account" type="submit" value="'. __( 'Delete', 'profile-builder' ) .'" />'; |
| 21 |
$output .= '<span class="wppb-description-delimiter">'.trim( html_entity_decode ( $item_description ) ).'</span>'; |
| 22 |
|
| 23 |
|
| 24 |
$delete_url = add_query_arg( array( |
| 25 |
'wppb_user' => $edited_user_id, |
| 26 |
'wppb_action' => 'wppb_delete_user', |
| 27 |
'wppb_nonce' => wp_create_nonce( 'wppb-user-own-account-deletion'), |
| 28 |
), home_url()); |
| 29 |
|
| 30 |
wp_enqueue_script( 'wppb-gdpr-delete-script', WPPB_PLUGIN_URL.'front-end/default-fields/gdpr-delete/gdpr-delete.js', array('jquery'), PROFILE_BUILDER_VERSION, true ); |
| 31 |
wp_localize_script('wppb-gdpr-delete-script', 'wppbGdpr', array( |
| 32 |
'delete_url' => $delete_url, |
| 33 |
'delete_text' => sprintf(__('Type %s to confirm deleting your account and all data associated with it:', 'profile-builder'), 'DELETE' ), |
| 34 |
'delete_error_text' => sprintf(__('You did not type %s. Try again!', 'profile-builder'), 'DELETE' ), |
| 35 |
)); |
| 36 |
|
| 37 |
return apply_filters( 'wppb_'.$form_location.'_gdpr_delete_custom_field_'.$field['id'], $output, $form_location, $field, $user_id, $field_check_errors, $request_data ); |
| 38 |
} |
| 39 |
} |
| 40 |
} |
| 41 |
add_filter( 'wppb_output_form_field_gdpr-delete-button', 'wppb_gdpr_delete_handler', 10, 6 ); |
| 42 |
|
| 43 |
|