Skip Navigation

[Résolu] ad a delete user button

This support ticket is created Il y a 1 année et 7 mois. There's a good chance that you are reading advice that it now obsolete.

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.

Aucun de nos assistants n'est disponible aujourd'hui sur le forum Jeu d'outils. Veuillez créer un ticket, et nous nous le traiterons dès notre prochaine connexion. Merci de votre compréhension.

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)

Ce sujet contient 3 réponses, a 2 voix.

Dernière mise à jour par Luo Yang Il y a 1 année et 7 mois.

Assisté par: Luo Yang.

Auteur
Publications
#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:
lien caché

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

3) Setup the custom PHP codes as below:
lien caché
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:
lien caché

It works fine. For your reference.

#2596811

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

#2596831

Login URL: lien caché