[Resolved] Account Deletion does not send an email and neither does it show confirmation
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
I am looking to give user the ability to delete their account via a toolset form.
Code used for deletion:
<?php
/**
* New custom code snippet (replace this with snippet description).
*/
toolset_snippet_security_check() or die( 'Direct access is not allowed' );
// Put the code of your snippet below this comment.
add_action('cred_save_data', 'deleteuser_v1', 10, 2);
function deleteuser_v1($post_id, $form_data)
{
if ($form_data['id'] == form-id)
{
$userid = $post_id;
//only delete if user is subscriber or member but not admin
$user = wp_get_current_user();
$user_roles = (array) $user->roles;
if ( in_array( 'subscriber', $user_roles ) || in_array( 'member', $user_roles ) && ( !in_array( 'employer', $user_roles ) || !in_array( 'administrator', $user_roles )) ) {
wp_delete_user( $userid );
} // if to ensure only subscriber or member is deleted
} // right form
} // end of function
It works to delete the account but it does not send an email to Admin and it does not show the confirmation message (setup on the form) to the user from Toolset form.
I tried and this does not work . The user does not get deleted.
add_filter('cred_success_redirect', 'deleteuser_v1',10,3);
function deleteuser_v1($url, $post_id, $form_data)
{
if ($form_data['id'] == form-id)
{
$userid = $post_id;
//only delete if user is subscriber or member but not admin
$user = wp_get_current_user();
$user_roles = (array) $user->roles;
if ( in_array( 'subscriber', $user_roles ) || in_array( 'member', $user_roles ) && ( !in_array( 'employer', $user_roles ) || !in_array( 'administrator', $user_roles )) ) {
wp_delete_user( $userid );
} // if to ensure only subscriber or member is deleted
} // right form
return $url;
} // end of function
I'll recommend a different approach where the the actual user account deletion process is not directly linked to the form's processing.
For example, after successful submission of the form, you can redirect the visitor to a secret/special page. On that page you can load a custom shortcode that deletes the current user who visits the page, using the same 'wp_delete_user' function.
This way the form's own operations like email notification won't be affected by the user deletion.
This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.