Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions includes/class-map-co-authors.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ public static function add_co_author( int $post_id, int $user_id ): bool {
return false;
}

if ( ! get_userdata( $user_id ) ) {
return false;
}

// The post's original author never needs to be stored as a co-author.
if ( (int) $post->post_author === $user_id ) {
return true;
Expand Down
5 changes: 5 additions & 0 deletions tests/Test_Co_Authors.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public function test_get_co_authors_returns_empty_array_by_default(): void {
$this->assertSame( array(), Co_Authors::get_co_authors( $this->post_id ) );
}

public function test_add_co_author_rejects_nonexistent_user(): void {
$this->assertFalse( Co_Authors::add_co_author( $this->post_id, 999999 ) );
$this->assertNotContains( 999999, Co_Authors::get_co_authors( $this->post_id ) );
}

public function test_add_co_author_returns_true(): void {
$this->assertTrue( Co_Authors::add_co_author( $this->post_id, $this->user_id ) );
}
Expand Down