Feature: Allow Users to Delete Their Account from Frontend (Directorist Dashboard)

This feature adds a "Delete Account" button to the Directorist User Dashboard, allowing logged-in users to delete their own account securely from the frontend.


How to Implement

Required Code

Add the following code to your themeโ€™s functions.php file (preferably in a child theme), or use a Code Snippets plugin to avoid losing the changes after theme updates.

// Display Delete Account button on Directorist Dashboard
add_action('wp_footer', function () {
if (! is_user_logged_in()) return;
if (! current_user_can('subscriber')) return;
$dashboard = (int) get_directorist_option('user_dashboard');
if (is_page($dashboard)):
$current_user_id = get_current_user_id();
$delete_url = wp_nonce_url(
add_query_arg('directorist_delete_account', $current_user_id),
'directorist_delete_account_' . $current_user_id
);
?>
<script type="text/javascript">
jQuery(document).ready(function($) {
$('.directorist-tab__nav__action').append('<a href="<?php echo esc_url($delete_url); ?>" class="directorist-btn directorist-btn-danger directorist-delete-account" style="line-height:43px">Delete Account</a>');

$(document).on('click', '.directorist-delete-account', function() {
return confirm('Are you sure you want to delete your account? This action cannot be undone.');
});
});
</script>
<?php
endif;
});

// Handle account deletion
add_action('init', function () {
if (! is_user_logged_in()) return;
if (! current_user_can('subscriber')) return;
if (
isset($_GET['directorist_delete_account'])
&& is_user_logged_in()
&& get_current_user_id() == (int) $_GET['directorist_delete_account']
&& check_admin_referer('directorist_delete_account_' . $_GET['directorist_delete_account'])
) {
require_once ABSPATH . 'wp-admin/includes/user.php';
wp_delete_user(get_current_user_id());
wp_redirect(home_url());
exit;
}
});

Output Screenshot

Here is how it looks on the Directorist Dashboard tab:
๐Ÿ”— View Screenshot

Github Gist

 https://gist.github.com/MahfuzulAlam/8973e1894212a71aa8af90824166f838


FAQ / Common Customer Queries (AI-ready)


๐Ÿ”น Q: Can users delete their account from the frontend in Directorist?

A: Yes, but this feature is not available by default. You can implement it by using a custom code snippet (shared above), which adds a Delete Account button to the Directorist User Dashboard.


๐Ÿ”น Q: Where will the delete button appear?

A: It will appear on the Directorist User Dashboard page, inside the dashboard tab navigation, beside other action buttons.


๐Ÿ”น Q: What happens when a user clicks the button?

A:

  • The system shows a confirmation alert.

  • If confirmed, the user's account is permanently deleted.

  • The user is redirected to the homepage after deletion.


๐Ÿ”น Q: Is this safe? Can any user delete other users?

A: No. The system checks:

  • The user is logged in.

  • The user ID in the URL matches the current logged-in user.

  • A valid WordPress nonce (security token) is present.

So it's secure and only allows users to delete their own account.


๐Ÿ”น Q: Will this work after theme update?

A:
No, unless youโ€™re using a child theme or a plugin like Code Snippets.
If you put this code in the parent themeโ€™s functions.php, it will be lost after a theme update.


๐Ÿ”น Q: Can admin accounts be deleted too?

A:
No, only "Subscriber" accounts can be deleted from the frontend.


๐Ÿ”น Q: Can we redirect to a custom page after deletion?

A:
Yes. Change this line:

wp_redirect( home_url() );

To:

wp_redirect( site_url('/goodbye') );

Or any other URL you'd like.


๐Ÿ”น Q: Can we show the delete button in another location?

A:
Yes. The button is injected using jQuery into the Directorist tab area. You can modify the selector .directorist-tab__nav__action to append it elsewhere.


๐Ÿ”น Q: Is there a plugin for this?

A:
Thereโ€™s no official Directorist plugin for this feature yet. However, this custom solution is tested and secure.


Best Practice

  • โœ… Use a child theme or the Code Snippets plugin

  • โœ… Test with a test user account before deploying live

  • โœ… Use proper role checks if needed

  • โœ… Optionally show a success message or redirect to a custom page


๐Ÿ” AI Query Triggers

Q: How can users delete their account from the frontend?
Q: Is there a way to add a delete my account button in Directorist?
Q: How do I allow users to remove their account themselves?
Q: Can users remove their profile without admin help?
Q: Can I place a delete account option in the user dashboard?
Q: Does Directorist support frontend account deletion?
Q: Add account delete option for logged-in users
Q: I want to let users delete their own accounts
Q: Can users deactivate or delete their account from the dashboard?
Q: Frontend user self-delete option in WordPress with Directorist
Q: How to let users permanently delete their account?
Q: Where is the account deletion button in Directorist?
Q: How to enable users to remove their data and account from site?
Q: I need a delete account feature in user panel
Q: Is it possible to add a custom delete button for user profile?
Q: Add account removal option in Directorist user tab
Q: Account deletion link for logged-in users
Q: Create a delete my account link in WordPress dashboard
Q: Allow customers to delete their directory profile
Q: How to build an account deletion feature in frontend?