Skip to content

Commit

Permalink
Fix error in featured_media property for WP_User
Browse files Browse the repository at this point in the history
Co-authors who are WordPress users do not have a type property. So checking it to make sure they are a guest author fails.
  • Loading branch information
douglas-johnson committed Nov 6, 2023
1 parent db08cc8 commit f1f0eda
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions php/api/endpoints/class-coauthors-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,17 @@ public function get_item( $request ) {
* @param WP_User|stdClass $coauthor
*/
public static function is_coauthor( $coauthor ): bool {
return is_a( $coauthor, 'WP_User' ) || ( property_exists( $coauthor, 'type' ) && 'guest-author' === $coauthor->type );
return is_a( $coauthor, 'WP_User' ) || self::is_guest_author( $coauthor );
}

/**
* Is Guest Author
*
* @since 3.6.0
* @param WP_User|stdClass $coauthor
*/
public static function is_guest_author( $coauthor ): bool {
return property_exists( $coauthor, 'type' ) && 'guest-author' === $coauthor->type;
}

/**
Expand Down Expand Up @@ -349,7 +359,11 @@ public function prepare_item_for_response( $author, $request ) {
}

if ( rest_is_field_included( 'featured_media', $fields ) ) {
$data['featured_media'] = (int) ( 'guest-author' === $author->type ? get_post_thumbnail_id( $author->ID ) : 0 );
if ( self::is_guest_author( $author ) ) {
$data['featured_media'] = (int) get_post_thumbnail_id( $author->ID );
} else {
$data['featured_media'] = 0;
}
}

if ( rest_is_field_included( 'user_nicename', $fields ) ) {
Expand Down

0 comments on commit f1f0eda

Please sign in to comment.