BuddyDev

Search

[Resolved] Don’t delete buddupress user, just saw him a msg.

  • Participant
    Level: Enlightened
    Posts: 71
    Lefteris on #48460

    Hello great buddydev team 🙂

    I would like to ask your help on my below function please.
    What i am trying to implement:

    1.When the buddypress user (that is not with a subscriber role) decides to delete his account, don’t actually delete his account and log him out. Just saw him a message ‘Your account will be deleted as you requested, within 24 hours’.
    2.At the same time send an email to admin.

    add_action( 'delete_user', 'prevent_buddypress_user_delete', 10, 1 );
    
    function prevent_buddypress_user_delete( $user_id ) {
        // Check if the user is a BuddyPress user
        if ( function_exists( 'buddypress' ) && buddypress()->is_active() && bp_is_active( 'xprofile' ) ) {
            $user = get_user_by( 'id', $user_id );
            
            // Check if the user is a subscriber
            if ( ! in_array( 'subscriber', $user->roles ) ) {
                // Send an email to the site administrators
                $to = get_option( 'admin_email' );
                $subject = 'User account deletion request';
                $message = sprintf( 'User %s has requested to delete their account. Please review this request and take appropriate action.', $user->user_login );
                wp_mail( $to, $subject, $message );
                
                // Display a message to the user
                bp_core_add_message( __( 'Your account will be deleted as you requested, within 24 hours.' ) );
                
                // Prevent the user from being deleted    ???
            }
        }
    }

    I am not sure if i am on the correct path and how could i prevent the deletion.

    Thank you for your time and your as always great help.

  • Keymaster
    (BuddyDev Team)
    Posts: 24623
    Brajesh Singh on #48478

    Hi Lefteris ,
    Thank you for the question.

    I am sorry, I am unable to look into the code and assist with it currently.

    My suggestion will be to use Deactivate Account plugin and enable it for the roles. Use localization to achieve the message. When a user deactivates their account, you will get an email and delete them.

    That is almost same experience.

    Regards
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 71
    Lefteris on #48491

    Hello Brajesh,

    Thank you for your help.
    I will look into the plugin.

    Best Regards
    Lefteris

  • Keymaster
    (BuddyDev Team)
    Posts: 24623
    Brajesh Singh on #48508

    You are welcome.

You must be logged in to reply to this topic.

This topic is: resolved