Skip to content

Commit fdf9848

Browse files
authored
User: Don't fall back to global post when looking for avatar (#1460)
* User: Don't fall back to global post when looking for avatar * Make test pass * Changelog
1 parent b91b6bd commit fdf9848

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
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+
Follow-Me blocks now show the correct avatar on attachment pages.

includes/model/class-user.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public function get_preferred_username() {
173173
*/
174174
public function get_icon() {
175175
$icon = \get_user_option( 'activitypub_icon', $this->_id );
176-
if ( wp_attachment_is_image( $icon ) ) {
176+
if ( false !== $icon && wp_attachment_is_image( $icon ) ) {
177177
return array(
178178
'type' => 'Image',
179179
'url' => esc_url( wp_get_attachment_url( $icon ) ),

tests/includes/class-test-move.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function test_account_with_invalid_user() {
7878
*/
7979
public function test_account_with_invalid_target() {
8080
$from = Actors::get_by_id( self::$user_id )->get_id();
81-
$to = 'https://invalid-url.com/user/1';
81+
$to = 'https://example.com/user/1';
8282

8383
$filter = function () {
8484
return new \WP_Error( 'http_request_failed', 'Invalid URL' );

tests/includes/model/class-test-user.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,26 @@ public function test_activitypub_cap() {
4848

4949
$this->assertTrue( $can );
5050
}
51+
52+
/**
53+
* Test that on attachment pages the user avatar is returned.
54+
*
55+
* @ticket https://github.com/Automattic/wordpress-activitypub/issues/1459
56+
* @covers ::get_icon
57+
*/
58+
public function test_icon() {
59+
$user_id = self::factory()->user->create( array( 'role' => 'author' ) );
60+
$user = User::from_wp_user( $user_id );
61+
62+
// Add attachment.
63+
$attachment_id = self::factory()->attachment->create_upload_object( AP_TESTS_DIR . '/assets/test.jpg' );
64+
65+
// Navigate to attachment page.
66+
$this->go_to( get_attachment_link( $attachment_id ) );
67+
68+
$icon = $user->get_icon();
69+
70+
$this->assertArrayHasKey( 'url', $icon );
71+
$this->assertNotSame( wp_get_attachment_url( $attachment_id ), $icon['url'] );
72+
}
5173
}

0 commit comments

Comments
 (0)