Skip to content

Commit 0ba13f9

Browse files
authored
Respect WordPress "show avatars" setting for remote actors (#2611)
1 parent 33179e1 commit 0ba13f9

File tree

9 files changed

+36
-17
lines changed

9 files changed

+36
-17
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: fixed
3+
4+
Respect WordPress "show avatars" setting for remote actor avatars.

build/followers/index.asset.php

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/followers/index.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/followers/render.php

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

includes/class-avatars.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ public static function pre_get_avatar_data( $args, $id_or_email ) {
4747
return $args;
4848
}
4949

50+
// Respect WordPress "show avatars" setting.
51+
if ( ! \get_option( 'show_avatars' ) ) {
52+
return $args;
53+
}
54+
5055
$avatar = null;
5156

5257
// First, try to get avatar from remote actor.

includes/class-blocks.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public static function enqueue_editor_assets() {
4646
'user' => \admin_url( 'profile.php#activitypub' ),
4747
'blog' => \admin_url( 'options-general.php?page=activitypub&tab=blog-profile' ),
4848
),
49+
'showAvatars' => (bool) \get_option( 'show_avatars' ),
4950
);
5051
wp_localize_script( 'wp-editor', '_activityPubOptions', $data );
5152

includes/collection/class-remote-actors.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -663,9 +663,11 @@ public static function get_acct( $id ) {
663663
*
664664
* @param int $id The ID of the remote actor post.
665665
*
666-
* @return string The avatar URL or empty string if not found.
666+
* @return string The avatar URL or a default one if not found.
667667
*/
668668
public static function get_avatar_url( $id ) {
669+
$default_avatar_url = ACTIVITYPUB_PLUGIN_URL . 'assets/img/mp.jpg';
670+
669671
$avatar_url = \get_post_meta( $id, '_activitypub_avatar_url', true );
670672
if ( $avatar_url ) {
671673
return $avatar_url;
@@ -674,12 +676,11 @@ public static function get_avatar_url( $id ) {
674676
// If not found in meta, try to extract from post_content JSON and cache it.
675677
$post = \get_post( $id );
676678
if ( ! $post || empty( $post->post_content ) ) {
677-
return '';
679+
return $default_avatar_url;
678680
}
679681

680682
$actor_data = \json_decode( $post->post_content, true );
681683
if ( empty( $actor_data['icon'] ) ) {
682-
$default_avatar_url = ACTIVITYPUB_PLUGIN_URL . 'assets/img/mp.jpg';
683684
\update_post_meta( $id, '_activitypub_avatar_url', \esc_url_raw( $default_avatar_url ) );
684685

685686
return $default_avatar_url;

src/followers/edit.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -263,21 +263,23 @@ function Pagination( { page, pages, setPage } ) {
263263
*/
264264
function Follower( { name, icon, url, preferredUsername } ) {
265265
const handle = `@${ preferredUsername }`;
266-
const { defaultAvatarUrl } = useOptions();
266+
const { defaultAvatarUrl, showAvatars } = useOptions();
267267
const avatar = icon?.url || defaultAvatarUrl;
268268

269269
return (
270270
<a className="follower-link" href={ url } title={ handle } onClick={ ( event ) => event.preventDefault() }>
271-
<img
272-
width="48"
273-
height="48"
274-
src={ avatar }
275-
className="follower-avatar"
276-
alt={ name }
277-
onError={ ( event ) => {
278-
event.target.src = defaultAvatarUrl;
279-
} }
280-
/>
271+
{ showAvatars && (
272+
<img
273+
width="48"
274+
height="48"
275+
src={ avatar }
276+
className="follower-avatar"
277+
alt={ name }
278+
onError={ ( event ) => {
279+
event.target.src = defaultAvatarUrl;
280+
} }
281+
/>
282+
) }
281283
<div className="follower-info">
282284
<span className="follower-name">{ name }</span>
283285
<span className="follower-username">{ handle }</span>

src/followers/render.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
}
4747

4848
$_per_page = absint( $attributes['per_page'] );
49+
$_show_avatars = (bool) \get_option( 'show_avatars' );
4950
$follower_data = Followers::query( $user_id, $_per_page );
5051

5152
// Prepare Followers data for the Interactivity API context.
@@ -115,6 +116,7 @@ class="follower-link"
115116
rel="external noreferrer noopener"
116117
data-wp-bind--title="context.item.handle">
117118

119+
<?php if ( $_show_avatars ) : ?>
118120
<img
119121
data-wp-bind--src="context.item.icon.url"
120122
data-wp-on--error="callbacks.setDefaultAvatar"
@@ -124,6 +126,7 @@ class="follower-avatar"
124126
width="48"
125127
height="48"
126128
>
129+
<?php endif; ?>
127130

128131
<div class="follower-info">
129132
<span class="follower-name" data-wp-text="context.item.name"></span>

0 commit comments

Comments
 (0)