I have a second user table in my WordPress database for a separate application that I am integrating. I need to be able to delete a user from this second table when the user is deleted in the WordPress admin. I understand that the the add_action hook I need to use is deleted_user, but what would I use as an identifier in the WHERE clause of $wpdb->delete query?


Using the delete_user action you can pass in the user_id and use that as a basis to delete the user from your addtiional table. This is, of course, assuming you use the user_id to make a relation between the two table. If not you can use get_userdata() passing in the user_id to get more user information. It would look something like this:

function custom_remove_user( $user_id ) {
    // $user_meta = get_userdata( $user_id );    // IF you need additional user info before removal
add_action( 'delete_user', 'custom_remove_user', 10 );
  • Thank you for the clarification! It worked like a charm! – Heather Feuerhelm Mar 17 '15 at 21:02
  • @HeatherFeuerhelm Great! If this was helpful be sure to upvote and click the checkmark so future readers know that this question was answered! – Howdy_McGee Mar 17 '15 at 21:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.