benecaster_avatar_uploaded
Fires after a subscriber successfully uploads a new avatar through the subscriber account page. At the point this action fires, the file has passed validation (2 MB maximum, JPEG/PNG/WebP, square dimensions), the attachment exists in the WordPress media library, the new attachment ID is written to user meta, and any previously uploaded avatar attachment has been deleted.
This hook does not fire when an upload fails validation or encounters a processing error. Use it to invalidate cached avatar URLs, sync the new avatar to an external profile system, or update a CDN entry.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$user_id |
int |
— | WordPress user ID |
$attachment_id |
int |
— | ID of the new avatar attachment |
Examples
Sync new avatar to CRM
add_action( 'benecaster_avatar_uploaded', function ( int $user_id, int $attachment_id ): void {
// Invalidate a cached avatar URL
delete_transient( 'my_avatar_url_' . $user_id );
// Sync to an external profile system
my_crm_update_avatar( $user_id, wp_get_attachment_url( $attachment_id ) );
}, 10, 2 );
Need this built rather than just documented? See our services →