diff --git a/includes/client/comments.php b/includes/client/comments.php index f74d9f4..182e058 100644 --- a/includes/client/comments.php +++ b/includes/client/comments.php @@ -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 "{$alt}"; +} ?> diff --git a/includes/init.php b/includes/init.php index d1fac39..afca981 100644 --- a/includes/init.php +++ b/includes/init.php @@ -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 ); ?>