+ /**
+ * Fires immediately before a user is deleted from the database.
+ *
+ * @since 2.0.0
+ *
+ * @param int $id ID of the user to delete.
+ * @param int|null $reassign ID of the user to reassign posts and links to.
+ * Default null, for no reassignment.
+ */
+ do_action( 'delete_user', $id, $reassign );
+
+ if ( null === $reassign ) {
+ $post_types_to_delete = array();
+ foreach ( get_post_types( array(), 'objects' ) as $post_type ) {
+ if ( $post_type->delete_with_user ) {
+ $post_types_to_delete[] = $post_type->name;
+ } elseif ( null === $post_type->delete_with_user && post_type_supports( $post_type->name, 'author' ) ) {
+ $post_types_to_delete[] = $post_type->name;
+ }
+ }
+
+ /**
+ * Filter the list of post types to delete with a user.
+ *
+ * @since 3.4.0
+ *
+ * @param array $post_types_to_delete Post types to delete.
+ * @param int $id User ID.
+ */
+ $post_types_to_delete = apply_filters( 'post_types_to_delete_with_user', $post_types_to_delete, $id );
+ $post_types_to_delete = implode( "', '", $post_types_to_delete );
+ $post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_author = %d AND post_type IN ('$post_types_to_delete')", $id ) );