post_author; if ( ! $author_id ) { return array(); } $url = get_avatar_url( $author_id, array( 'size' => 96 ) ); if ( ! $url ) { return array(); } return array( 'url' => esc_url_raw( $url ), 'alt' => (string) get_the_author_meta( 'display_name', $author_id ), 'source' => 'dynamic', ); } return array(); } /** Resolve the post's featured image at the configured size. */ private static function featured_image( WP_Post $post, array $config ) { $attachment_id = (int) get_post_thumbnail_id( $post ); if ( ! $attachment_id ) { return array(); } $size = isset( $config['imageSize'] ) && is_string( $config['imageSize'] ) ? sanitize_key( $config['imageSize'] ) : 'large'; $media = wp_get_attachment_image_src( $attachment_id, $size ); if ( ! $media ) { $media = wp_get_attachment_image_src( $attachment_id, 'full' ); } if ( ! $media ) { return array(); } return array( 'id' => $attachment_id, 'url' => esc_url_raw( $media[0] ), 'alt' => (string) get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ), 'width' => (int) $media[1], 'height' => (int) $media[2], 'srcset' => (string) wp_get_attachment_image_srcset( $attachment_id, $size ), 'source' => 'dynamic', ); } /** Use the manually selected fallback image when the post has no featured image. */ private static function fallback_image( array $config ) { $fallback = isset( $config['fallbackImage'] ) && is_array( $config['fallbackImage'] ) ? $config['fallbackImage'] : array(); $size = isset( $config['imageSize'] ) && is_string( $config['imageSize'] ) ? sanitize_key( $config['imageSize'] ) : 'large'; $sizes = isset( $fallback['sizes'] ) && is_array( $fallback['sizes'] ) ? $fallback['sizes'] : array(); $selected = isset( $sizes[ $size ] ) && is_array( $sizes[ $size ] ) ? $sizes[ $size ] : array(); $url = $selected['url'] ?? $selected['source_url'] ?? $fallback['url'] ?? $fallback['source_url'] ?? ''; if ( ! is_string( $url ) || '' === $url ) { return array(); } return array( 'id' => isset( $fallback['id'] ) ? (int) $fallback['id'] : null, 'url' => esc_url_raw( $url ), 'alt' => (string) ( $fallback['alt'] ?? $fallback['alt_text'] ?? '' ), 'width' => isset( $selected['width'] ) ? (int) $selected['width'] : null, 'height' => isset( $selected['height'] ) ? (int) $selected['height'] : null, 'source' => 'fallback', ); } /** Published posts, or posts the current user can read in the editor preview. */ private static function can_read( WP_Post $post ) { return 'publish' === $post->post_status || current_user_can( 'read_post', $post->ID ); } }