Created
March 2, 2023 08:49
-
-
Save endurtech/fbd54e62423121c18251be9a6c8c469e to your computer and use it in GitHub Desktop.
The following code, when inserted into a custom plugin or your child theme's functions.php file, will automatically delete the associated WordPress "Users" account when deleting a User from the "Trash" tab.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// GF Auto Delete User from WP Upon Form Entry Deletion | |
// If user entry (in members form) is trashed, then deleted from trash, they are also deleted from WP Users table. | |
// https://endurtech.com/delete-associated-wp-user-when-deleting-gravity-forms-entry/ | |
add_action( 'gform_delete_entry', function ( $entry_id ) | |
{ | |
if ( ! function_exists( 'gf_user_registration' ) ) | |
{ | |
return; | |
} | |
$user_id = gf_user_registration()->get_user_by_entry_id( $entry_id, true ); | |
wp_delete_user( $user_id ); | |
}); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment