benecaster_avatar_deleted
Fires when a subscriber removes their uploaded avatar through the subscriber account page. By the time this action runs the removal is complete: the subscriber is no longer recorded as having an avatar, and the image file has been deleted from the WordPress media library.
This hook does not fire on a repeat delete request — if the subscriber has no avatar at the time of the delete request, the action is skipped entirely. Pair with benecaster_avatar_uploaded for symmetric upload and remove handling, such as invalidating a cached avatar URL whenever either event occurs.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$user_id |
int |
— | WordPress user ID |
$attachment_id |
int |
— | ID of the avatar attachment that was removed |
Examples
Invalidate avatar cache on removal
add_action( 'benecaster_avatar_deleted', function ( int $user_id, int $attachment_id ): void {
// Invalidate cached avatar URL
delete_transient( 'my_avatar_url_' . $user_id );
// Log removal for audit purposes
my_audit_log( 'avatar_removed', [ 'user_id' => $user_id ] );
}, 10, 2 );
Need this built rather than just documented? See our services →