Problem:
Is it possible to have a link on the front-end users can use to delete their account?
Solution:
1. Make sure the settings when editing the custom post type at Toolset > Post Types under "Sections to display when editing..." include the author option.
2. Create a CRED form to edit users, which need include only a "Delete User" button, like so:
[creduserform class='cred-user-form cred-keep-original'] [cred_field field='form_submit' value='Delete User' urlparam='' class='btn btn-primary btn-lg' output='bootstrap'] [/creduserform]
3. Add the following code to your theme's functions.php file or using a plugin such as Code Snippets, being sure to edit the id of the form created in the previous step:
/** * Hook into CRED Edit User form submission * to delete current user */ function tssupp_delete_user( $post_id, $form_data ){ if ( 203 == $form_data['id'] ) { require_once( ABSPATH.'wp-admin/includes/user.php' ); $current_user = get_current_user_id(); wp_delete_user( $current_user ); } } add_action( 'cred_submit_complete', 'tssupp_delete_user', 10, 2 );
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.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
- | 7:00 – 14:00 | 7:00 – 14:00 | 7:00 – 14:00 | 7:00 – 14:00 | 7:00 – 14:00 | - |
- | 15:00 – 16:00 | 15:00 – 16:00 | 15:00 – 16:00 | 15:00 – 16:00 | 15:00 – 16:00 | - |
Supporter timezone: Europe/London (GMT+00:00)
This topic contains 11 replies, has 3 voices.
Last updated by 6 years, 10 months ago.
Assisted by: Nigel.