Repository navigation
Theme and Plugin Integration
WP User Avatars integrates with WordPress's native avatar APIs. Themes and plugins do not need a plugin-specific display function.
Use get_avatar() when WordPress should create the image markup:
echo get_avatar( get_the_author_meta( 'ID' ), 96 );Use get_avatar_url() when another component needs the URL:
$avatar_url = get_avatar_url(
$user_id,
array(
'size' => 256,
)
);Ask WordPress for the size the layout will display. Enlarging a 96 pixel URL
with CSS cannot recover missing detail. get_avatar() also requests a 2x source
for high-density displays when the original image is large enough.
Pass meaningful alternative text as the fourth argument when the avatar conveys information:
echo get_avatar( $user_id, 96, '', 'Portrait of Jane Doe' );Leave the value empty when nearby text already identifies the person and the avatar is decorative. WP User Avatars supplies the image URL and preserves the caller's alternative text. It does not copy alternative text from a Media Library attachment.
Use the block or shortcode for content-managed pages. Code can render the same editor for the current signed-in user:
echo wp_user_avatars_get_editor();Call the helper in a normal front-end template where WordPress has loaded the plugin. The renderer enqueues its required assets.
Direct uploads create a square derivative when WordPress first requests an uncached size. Disable future plugin-owned resizing:
add_filter( 'wp_user_avatars_dynamic_resize', '__return_false' );Or allow only selected sizes:
add_filter(
'wp_user_avatars_dynamic_resize',
function ( $resize, $user_id, $size ) {
$allowed_sizes = array( 96, 192, 256, 512 );
return $resize && in_array( (int) $size, $allowed_sizes, true );
},
10,
3
);A disallowed uncached request falls back to the original image. Existing derivatives are not deleted. A direct upload or locally stored Media Library attachment follows the plugin's local square-derivative path. A remotely stored Media Library attachment continues through WordPress's attachment image-size resolution.
The primary integration functions are:
wp_user_avatars_get_editor()wp_user_avatars_get_local_avatar_url()wp_user_avatars_update_avatar()wp_user_avatars_delete_avatar()wp_user_avatars_update_rating()
User avatar data is stored in wp_user_avatars. The rating is stored in
wp_user_avatars_rating. Prefer the public update and delete functions instead
of writing those keys directly.