Support » Plugin: User Taxonomies » [NOTE]: add delete_user action to handle info properly

  • Hello,

    This is for the information – when a user is deleted, the associated information about her/his User Taxonomy Terms are still stored in the DB. To make sure it’s all cleaned up when a user is deleted, please add the following:

    1. Add the following to the __construct() method:

    // Delete associated user taxonomy terms info when a user is deleted
    add_action('delete_user', array($this, 'delete_user'));

    2. Add delete_user method to the class as following:

     * Delete all associated user taxonomy terms for a user that's being deleted
     * @param Integer $user_id	- The user ID that is being deleted
    public function delete_user( $user_id ) {
      // Get all User Taxonomy names that are stored as keys in the class variable $taxonomies
      // Delete all associated terms from these taxonomies for the user that's being deleted
      if ( is_array( self::$taxonomies ) && !empty( self::$taxonomies ) ) {
        $taxonomy_names = array_keys( self::$taxonomies );
        wp_delete_object_term_relationships( $user_id, $taxonomy_names );

    I hope that helps someone.


  • The topic ‘[NOTE]: add delete_user action to handle info properly’ is closed to new replies.