Changeset 57377 for trunk/src/wp-includes/blocks/post-featured-image.php
- Timestamp:
- 01/29/2024 09:04:18 PM (17 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/blocks/post-featured-image.php
r56710 r57377 55 55 56 56 $featured_image = get_the_post_thumbnail( $post_ID, $size_slug, $attr ); 57 58 // Get the first image from the post. 59 if ( $attributes['useFirstImageFromPost'] && ! $featured_image ) { 60 $content_post = get_post( $post_ID ); 61 $content = $content_post->post_content; 62 $processor = new WP_HTML_Tag_Processor( $content ); 63 64 /* 65 * Transfer the image tag from the post into a new text snippet. 66 * Because the HTML API doesn't currently expose a way to extract 67 * HTML substrings this is necessary as a workaround. Of note, this 68 * is different than directly extracting the IMG tag: 69 * - If there are duplicate attributes in the source there will only be one in the output. 70 * - If there are single-quoted or unquoted attributes they will be double-quoted in the output. 71 * - If there are named character references in the attribute values they may be replaced with their direct code points. E.g. `…` becomes `…`. 72 * In the future there will likely be a mechanism to copy snippets of HTML from 73 * one document into another, via the HTML Processor's `get_outer_html()` or 74 * equivalent. When that happens it would be appropriate to replace this custom 75 * code with that canonical code. 76 */ 77 if ( $processor->next_tag( 'img' ) ) { 78 $tag_html = new WP_HTML_Tag_Processor( '<img>' ); 79 $tag_html->next_tag(); 80 foreach ( $processor->get_attribute_names_with_prefix( '' ) as $name ) { 81 $tag_html->set_attribute( $name, $processor->get_attribute( $name ) ); 82 } 83 $featured_image = $tag_html->get_updated_html(); 84 } 85 } 86 57 87 if ( ! $featured_image ) { 58 88 return ''; 59 89 } 90 60 91 if ( $is_link ) { 61 92 $link_target = $attributes['linkTarget'];
Note: See TracChangeset
for help on using the changeset viewer.