Skip Navigation

[Resolved] ad a delete user button

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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 3 replies, has 2 voices.

Last updated by Luo Yang 1 year, 7 months ago.

Assisted by: Luo Yang.

Author
Posts
#2596573

Tell us what you are trying to do?
I want the website administrator to be able to delete a user via a button located on a user profile sheet displayed in a view."

Is there any documentation that you are following?
https://toolset.com/forums/topic/add-the-link-delete-account/#post-606430

i've created a user edit form (id 30047) with this code :

[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]

and puted this code in function.php

function bethesda_delete_user( $post_id, $form_data ){

if ( 30047 == $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', 'bethesda_delete_user', 10, 2 );

the button appears in the view but when i click on it it reloads the page and nothing appears....

#2596807

Hello,

The thread you mentioned above is for deleting current logged-in user.

In your case, you need to modify the custom PHP codes, see below test site:
1) Create a user form for editing user:
hidden link

2) In the user view, display above user form shortcode:
hidden link
[cred_user_form form='ad-a-delete-user-button' user='[wpv-user field="ID"]']

3) Setup the custom PHP codes as below:
hidden link
line 659~666

function bethesda_delete_user( $user_id, $form_data ){
  if ( 43 == $form_data['id'] ) {

    require_once( ABSPATH.'wp-admin/includes/user.php' );
    wp_delete_user( $user_id );
  }
}
add_action( 'cred_submit_complete', 'bethesda_delete_user', 10, 2 );

Test it in frontend:
hidden link

It works fine. For your reference.

#2596811

can you give me the login and the pass for the test site ?

#2596831

Login URL: hidden link