image_id(); if ( ! $image_id ) { return $value; } $post_type = get_post_type( $object_id ); if ( false === $post_type || ! in_array( $post_type, $this->supported_post_types(), true ) ) { return $value; } $cache = wp_cache_get( $object_id, 'post_meta' ); if ( ! $cache ) { $cache = update_meta_cache( 'post', array( $object_id ) ); $cache = $cache[ $object_id ] ?? array(); } if ( ! empty( $cache['_thumbnail_id'][0] ) ) { return $value; } /** * Filters the fallback attachment id used for a given post. * * @since 2.0.0 */ $cache['_thumbnail_id'][0] = (string) apply_filters( 'aiou_featured_image_fallback_id', $image_id, $object_id ); wp_cache_set( $object_id, $cache, 'post_meta' ); return $value; } /** * Render the fallback image's HTML with a distinguishing CSS class. * * @param string $html Existing HTML (already generated for the fallback thumbnail id). * @param int $post_id Post ID. * @param int $post_thumbnail_id Thumbnail attachment ID being rendered. * @param string|int[] $size Requested image size. * @param string|array $attr Query string or array of attributes. * @return string */ public function render_thumbnail_html( string $html, int $post_id, int $post_thumbnail_id, $size, $attr ): string { $image_id = $this->image_id(); if ( ! $image_id || $image_id !== $post_thumbnail_id ) { return $html; } if ( is_string( $attr ) ) { wp_parse_str( $attr, $attr ); } $attr = (array) $attr; $attr['class'] = trim( ( $attr['class'] ?? '' ) . ' aiou-default-featured-image' ); $html = wp_get_attachment_image( $image_id, $size, false, $attr ); /** * Filters the fallback featured image HTML. * * @since 2.0.0 */ return apply_filters( 'aiou_featured_image_html', $html, $post_id, $image_id, $size, $attr ); } }