Render Fediverse avatars

This commit is contained in:
Jeremy Dormitzer 2018-11-09 22:27:28 -05:00
parent e8d59df0a9
commit 1d68270faa
2 changed files with 31 additions and 0 deletions

View File

@ -184,4 +184,33 @@ function traverse_reply_chain_helper( $object, $depth, $acc ) {
$parent, $depth + 1, array_values( array_unique( array_merge( $acc, $recipients ) ) )
);
}
function get_avatar_filter( $avatar, $comment, $size, $default, $alt ) {
if ( ! is_object( $comment ) || ! isset( $comment->comment_ID ) ) {
return $avatar;
}
$comment_id = $comment->comment_ID;
$object_id = \pterotype\commentlinks\get_object_id( $comment_id );
if ( ! $object_id ) {
return $avatar;
}
$object = \pterotype\objects\get_object( $object_id );
if ( ! $object || is_wp_error( $object ) || ! array_key_exists( 'actor', $object ) ) {
return $avatar;
}
$actor = \pterotype\util\dereference_object( $object['actor'] );
if ( ! $actor || is_wp_error( $actor ) || ! array_key_exists( 'icon', $actor ) ) {
return $avatar;
}
$icon = $actor['icon'];
if ( ! $icon || ! is_array( $icon ) || ! array_key_exists( 'url', $icon ) ) {
return $avatar;
}
$src = $icon['url'];
return "<img alt='{$alt}'
src='{$src}'
class='avatar avatar-{$size}'
height='{$size}'
width='{$size}' />";
}
?>

View File

@ -98,4 +98,6 @@ add_action( 'admin_menu', function() {
\pterotype\settings\register_settings_sections();
\pterotype\settings\register_settings_fields();
} );
add_filter( 'get_avatar', '\pterotype\comments\get_avatar_filter', 10, 5 );
?>