From f262210eed0ab6fac51a7750d8822a0712fc9f99 Mon Sep 17 00:00:00 2001 From: Douglas Johnson Date: Mon, 6 Nov 2023 17:46:36 -0500 Subject: [PATCH] Fix error in featured_media property for WP_User Co-authors who are WordPress users do not have a type property. So checking it to make sure they are a guest author fails. --- .../endpoints/class-coauthors-controller.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/php/api/endpoints/class-coauthors-controller.php b/php/api/endpoints/class-coauthors-controller.php index 33aaa573..7faef532 100644 --- a/php/api/endpoints/class-coauthors-controller.php +++ b/php/api/endpoints/class-coauthors-controller.php @@ -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; } /** @@ -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 ) ) {