Skip Navigation

[Résolu] Front-end delete account function pt.2

Ce fil est résolu. Voici une description du problème et la solution proposée.

Problem: I would like to use a Form to delete a User. When the Form is submitted successfully, I would like to send an email to that User's address.

Solution: Add a generic hidden field to the Form and call it something like "generic-email-field". Set the value to be the current User's email, like this:

[cred_generic_field type='hidden' field='generic-email-field']
{
"required":0,
"validate_format":0,
"default":"[wpv-user field='user_email']"
}
[/cred_generic_field]

Then in the notification settings, I would choose "Send notification to a specific email address" and enter something like support@yoursite.com, where all these messages will be sent. Then you can use the cred_notification_recipients API to add the generic field address as a CC, like this:

add_filter('cred_notification_recipients', 'modify_recipients', 10, 4);
function modify_recipients($recipients, $notification, $form_id, $post_id) {
    // Check notification name matches target notification
    if ( isset($notification['name']) && 'Your notification name' == $notification['name'] ) {
        // Add a CC to the generic email address 
        $recipients[] = array(
            'to'        =>  'cc',
            'address'   => $_POST['generic-email-field'],
            'name'      =>  '',
            'lastname'  =>  ''
            );
    }
    return $recipients;
}

Change Your notification name to match your notification name.

Relevant Documentation:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_notification_recipients

This support ticket is created Il y a 5 années et 8 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

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

Dernière mise à jour par diyanK Il y a 5 années et 8 mois.

Assisté par: Christian Cox.

Auteur
Publications
#1223440

Hi team,

I'm trying to create fully functional delete (self) account feature on my project and I need a little help.

I started with the guide from this ticket:
https://toolset.com/forums/topic/add-the-link-delete-account/#post-1223439

The method works and deletes the custom user and his custom posts.

However after the user is deleted and redirected back to the homepage there is no actual feedback to what happened to them.

I can't seem to figure out how to send an email notification to a form submission that does not have an email field inside.

Also the option to show a message after submitting the form does nothing on my setup, just adds some parameters to the url.

Also I would like to clean up the uploads folder by deleting the dedicated user folder. Right now every user has his own folder named after his ID with the following function:

/* #2 Per user upload dir function */
function per_user_upload_dir( $original ){
    // use the original array for initial setup
    $modified = $original;
    // set our own replacements
    if ( is_user_logged_in() ) {
        $current_user = wp_get_current_user();
        $subdir = $current_user->ID;
        $modified['subdir'] = $subdir;
        $modified['url'] = $original['baseurl'] . '/' . $subdir;
        $modified['path'] = $original['basedir'] . DIRECTORY_SEPARATOR . $subdir;
    }
    return $modified;
}
add_filter( 'upload_dir', 'per_user_upload_dir'); 

How can I trigger a an action that would delete the folder named after the user's ID on form submission?

Also how about a working confirmation msg that shows on the homepage once the user gets redirected back to it after deletion?

Thanks in advance!
Diyan

#1223595

I can't seem to figure out how to send an email notification to a form submission that does not have an email field inside.
This is a tricky one because the User gets deleted before the notification is actually sent. I would add a generic hidden field to the Form and call it something like "generic-email-field". Set the value to be the current User's email, like this:

[cred_generic_field type='hidden' field='generic-email-field']
{
"required":0,
"validate_format":0,
"default":"[wpv-user field='user_email']"
}
[/cred_generic_field]

Then in the notification settings, I would choose "Send notification to a specific email address" and enter something like support@yoursite.com, where all these messages will be sent. Then you can use the cred_notification_recipients API to add the generic field address as a CC, like this:

add_filter('cred_notification_recipients', 'modify_recipients', 10, 4);
function modify_recipients($recipients, $notification, $form_id, $post_id) {
    // Check notification name matches target notification
    if ( isset($notification['name']) && 'Your notification name' == $notification['name'] ) {
        // Add a CC to the generic email address 
        $recipients[] = array(
            'to'        =>  'cc',
            'address'   => $_POST['generic-email-field'],
            'name'      =>  '',
            'lastname'  =>  ''
            );
    }
    return $recipients;
}

Change Your notification name to match your notification name. Documentation for this API is available here: https://toolset.com/documentation/programmer-reference/cred-api/#cred_notification_recipients

#1223627

Okay this seems to do the job very nicely! One more to go..