Skip to content

Commit 217e98c

Browse files
authored
Fix: Default value for empty movedTo field (#1539)
* Fix: Default value for empty `movedTo` field * Add changelog * fix phpcs issues * Add unit test
1 parent 30a0053 commit 217e98c

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+
So not show `movedTo` attribute instead of setting it to `false` if empty.

includes/model/class-blog.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,7 @@ public function get_also_known_as() {
576576
* @return string The movedTo.
577577
*/
578578
public function get_moved_to() {
579-
return \get_option( 'activitypub_blog_user_moved_to' );
579+
// phpcs:ignore Universal.Operators.DisallowShortTernary.Found
580+
return \get_option( 'activitypub_blog_user_moved_to' ) ?: null;
580581
}
581582
}

includes/model/class-user.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,7 @@ public function get_also_known_as() {
446446
* @return string The movedTo.
447447
*/
448448
public function get_moved_to() {
449-
return \get_user_option( 'activitypub_moved_to', $this->_id );
449+
// phpcs:ignore Universal.Operators.DisallowShortTernary.Found
450+
return \get_user_option( 'activitypub_moved_to', $this->_id ) ?: null;
450451
}
451452
}

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,24 @@ public function test_icon() {
7070
$this->assertArrayHasKey( 'url', $icon );
7171
$this->assertNotSame( wp_get_attachment_url( $attachment_id ), $icon['url'] );
7272
}
73+
74+
/**
75+
* Tests the get_moved_to method.
76+
*
77+
* @covers ::get_moved_to
78+
*/
79+
public function test_get_moved_to() {
80+
$user_id = self::factory()->user->create( array( 'role' => 'author' ) );
81+
$user = User::from_wp_user( $user_id );
82+
83+
// No value => should not even be set.
84+
$this->assertArrayNotHasKey( 'movedTo', $user->to_array( false ) );
85+
86+
// Set movedTo.
87+
\update_user_option( $user_id, 'activitypub_moved_to', 'https://example.com' );
88+
89+
$user = User::from_wp_user( $user_id )->to_array( false );
90+
$this->assertArrayHasKey( 'movedTo', $user );
91+
$this->assertSame( 'https://example.com', $user['movedTo'] );
92+
}
7393
}

0 commit comments

Comments
 (0)