Trying to implement a way for administrative users to remove other users via front end
Following thread here:
https://toolset.com/forums/topic/administrators-and-editors-option-to-delete-other-user-on-the-frontend/
I have added the code to functions.php, added the generic field with the user id and the submit button to the form, added the form to the loop. Form fires when submit is clicked, but user account is not deleted. I have updated the form ID in the code snippet.
Not sure what i am missing. Please enable private reply fields so I can give access. Thank you!
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi James,
Please allow me to have admin access to the site and a link to where the form is so that I can have a look at this one for you.
Thanks,
Shane
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi James,
I'm still looking into this for you, however what i've found is that the Hook isn't being triggered.
If I have any update for you I will let you know.
Thanks,
Shane
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi James,
I'm still looking into this for you, however what i've found is that the Hook isn't being triggered.
If I have any update for you I will let you know.
Thanks,
Shane
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi James,
Are you able to provide FTP access to the site ? If you take a look at your functions.php file in the child theme you will notice that I added a die() function. Can you remove it ?
This was added as a test to see if the functions.php file is being loaded correctly, however because of this i'm not able to access the site.
Please let me know once you've removed it.
Thanks,
Shane
It's removed and the site is working again.
Do you still need FTP access?
Do you still need FTP access, Shane?
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi James,
Yes please provide the FTP access .
I've enabled the private fields for your next response.
Thanks,
Shane
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi James,
This should now be working.
Not sure why your first form wasn't triggering the hook but now that i've created a completely new for you are now able to delete your users.
The updated code is now this.
/**
* Hook into CRED Edit User form submission
* to delete current user
*/
function tssupp_delete_user( $user_id, $form_data ){
if ( $form_data['id'] == 4809 ) {
require_once( ABSPATH.'wp-admin/includes/user.php' );
wp_delete_user( $user_id );
}
}
add_action( 'cred_save_data', 'tssupp_delete_user', 10, 2 );
Also you can pass the ID of the user directly to the form by doing it like this.
[cred_user_form form='delete-user-2' user="[wpv-user field='ID']"]
Please let me know if this helps.
Thanks,
Shane
ok, cool.
So, just so I understand, I don't NEED the intermediate generic field, is that correct?
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi James,
That is correct.
If you check the new form that I created "Delete User 2" you will notice that it only has the submit button.
Given that the ID is being passed directly to the form no intermediary field is required to hold the user's ID.
Thanks,
Shane
My issue is resolved now. Thank you!