Skip to content

Commit

Permalink
fix: PHPCS fixes and added commentary/descriptions to docblocks.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddiesshop committed Oct 17, 2023
1 parent a0b808a commit e3a120a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
11 changes: 7 additions & 4 deletions php/class-coauthors-plus.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ public function get_coauthor_by( $key, $value, $force = false ) {

return $guest_author;
} else {
// Guest Author was not found, so let's see if we are searching for a WP_User
// Guest Author was not found, so let's see if we are searching for a WP_User.
$user = $this->get_user_by( $key, $value );

if ( null === $user ) {
Expand Down Expand Up @@ -352,7 +352,10 @@ public function get_coauthor_by( $key, $value, $force = false ) {
}

/**
* @param string $key Key to search by, i.e. 'id', 'login', 'user_login', 'email', 'user_email', 'user_nicename'
* Searches for authors by way of the WP_User table using a specific list of data points. If login or slug
* are provided as search parameters, this function will remove `cap-` from the search value, if present.
*
* @param string $key Key to search by, i.e. 'id', 'login', 'user_login', 'email', 'user_email', 'user_nicename'.
* @param string $value Value to search for.
*
* @return WP_User|null
Expand All @@ -375,10 +378,10 @@ protected function get_user_by( $key, $value ) {

$user = get_user_by( $key, $value );

if ( ! $user && ( 'login' == $key || 'slug' == $key ) ) {
if ( ! $user && ( 'login' === $key || 'slug' === $key ) ) {
// Re-try lookup without prefixed value if no results found.
$value = preg_replace( '#^cap\-#', '', $value );
$user = get_user_by( $key, $value );
$user = get_user_by( $key, $value );
}

if ( false === $user ) {
Expand Down
15 changes: 10 additions & 5 deletions tests/Integration/CoAuthorsPlusTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace Automattic\CoAuthorsPlus\Tests\Integration;

use WP_Query;
use WP_Term;

class CoAuthorsPlusTest extends TestCase {

private $author1;
Expand Down Expand Up @@ -725,16 +728,18 @@ public function test_assign_post_author_from_author_who_has_not_been_linked() {
$post_id = $post->ID;

$first_added_authors = $this->_cap->add_coauthors( $post_id, array( $this->author3->user_login ) );
// add_coauthors should return true because CAP will treat this user as an Author with the
// extra step of setting wp_post.post_author equal to this user's wp_user.ID.
$this->assertTrue( $first_added_authors );

$query2 = new WP_Query(
$query1 = new WP_Query(
array(
'p' => $post_id
'p' => $post_id,
)
);

$this->assertEquals( 1, $query2->found_posts );
$this->assertEquals( $this->author3->ID, $query2->posts[0]->post_author );
// Checking that the wp_post.post_author column has indeed been updated.
$this->assertEquals( $this->author3->ID, $query1->posts[0]->post_author );

$author3_term = $this->_cap->get_author_term( $this->author3 );

Expand All @@ -747,7 +752,7 @@ public function test_assign_post_author_from_author_who_has_not_been_linked() {
$this->assertInstanceOf( WP_Term::class, $post_author_terms[0] );
$this->assertEquals( 'cap-' . $this->author3->user_login, $post_author_terms[0]->slug );

// Confirming that now $author2 does have an author term
// Confirming that now $author2 does have an author term.
$second_added_authors = $this->_cap->add_coauthors( $post_id, array( $this->author2->user_login ) );
$this->assertTrue( $second_added_authors );
$author2_term = $this->_cap->get_author_term( $this->author2 );
Expand Down

0 comments on commit e3a120a

Please sign in to comment.