Edit File by line
/home/zeestwma/richards.../wp-inclu.../blocks
File: media-text.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Server-side rendering of the `core/media-text` block.
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
/**
[7] Fix | Delete
* Renders the `core/media-text` block on server.
[8] Fix | Delete
*
[9] Fix | Delete
* @since 6.6.0
[10] Fix | Delete
*
[11] Fix | Delete
* @param array $attributes The block attributes.
[12] Fix | Delete
* @param string $content The block rendered content.
[13] Fix | Delete
*
[14] Fix | Delete
* @return string Returns the Media & Text block markup, if useFeaturedImage is true.
[15] Fix | Delete
*/
[16] Fix | Delete
function render_block_core_media_text( $attributes, $content ) {
[17] Fix | Delete
if ( false === $attributes['useFeaturedImage'] ) {
[18] Fix | Delete
return $content;
[19] Fix | Delete
}
[20] Fix | Delete
[21] Fix | Delete
if ( in_the_loop() ) {
[22] Fix | Delete
update_post_thumbnail_cache();
[23] Fix | Delete
}
[24] Fix | Delete
[25] Fix | Delete
$current_featured_image = get_the_post_thumbnail_url();
[26] Fix | Delete
if ( ! $current_featured_image ) {
[27] Fix | Delete
return $content;
[28] Fix | Delete
}
[29] Fix | Delete
[30] Fix | Delete
$has_media_on_right = isset( $attributes['mediaPosition'] ) && 'right' === $attributes['mediaPosition'];
[31] Fix | Delete
$image_fill = isset( $attributes['imageFill'] ) && $attributes['imageFill'];
[32] Fix | Delete
$focal_point = isset( $attributes['focalPoint'] ) ? round( $attributes['focalPoint']['x'] * 100 ) . '% ' . round( $attributes['focalPoint']['y'] * 100 ) . '%' : '50% 50%';
[33] Fix | Delete
$unique_id = 'wp-block-media-text__media-' . wp_unique_id();
[34] Fix | Delete
[35] Fix | Delete
$block_tag_processor = new WP_HTML_Tag_Processor( $content );
[36] Fix | Delete
$block_query = array(
[37] Fix | Delete
'tag_name' => 'div',
[38] Fix | Delete
'class_name' => 'wp-block-media-text',
[39] Fix | Delete
);
[40] Fix | Delete
[41] Fix | Delete
while ( $block_tag_processor->next_tag( $block_query ) ) {
[42] Fix | Delete
if ( $image_fill ) {
[43] Fix | Delete
// The markup below does not work with the deprecated `is-image-fill` class.
[44] Fix | Delete
$block_tag_processor->remove_class( 'is-image-fill' );
[45] Fix | Delete
$block_tag_processor->add_class( 'is-image-fill-element' );
[46] Fix | Delete
}
[47] Fix | Delete
}
[48] Fix | Delete
[49] Fix | Delete
$content = $block_tag_processor->get_updated_html();
[50] Fix | Delete
[51] Fix | Delete
$media_tag_processor = new WP_HTML_Tag_Processor( $content );
[52] Fix | Delete
$wrapping_figure_query = array(
[53] Fix | Delete
'tag_name' => 'figure',
[54] Fix | Delete
'class_name' => 'wp-block-media-text__media',
[55] Fix | Delete
);
[56] Fix | Delete
[57] Fix | Delete
if ( $has_media_on_right ) {
[58] Fix | Delete
// Loop through all the figure tags and set a bookmark on the last figure tag.
[59] Fix | Delete
while ( $media_tag_processor->next_tag( $wrapping_figure_query ) ) {
[60] Fix | Delete
$media_tag_processor->set_bookmark( 'last_figure' );
[61] Fix | Delete
}
[62] Fix | Delete
if ( $media_tag_processor->has_bookmark( 'last_figure' ) ) {
[63] Fix | Delete
$media_tag_processor->seek( 'last_figure' );
[64] Fix | Delete
// Insert a unique ID to identify the figure tag.
[65] Fix | Delete
$media_tag_processor->set_attribute( 'id', $unique_id );
[66] Fix | Delete
}
[67] Fix | Delete
} else {
[68] Fix | Delete
if ( $media_tag_processor->next_tag( $wrapping_figure_query ) ) {
[69] Fix | Delete
// Insert a unique ID to identify the figure tag.
[70] Fix | Delete
$media_tag_processor->set_attribute( 'id', $unique_id );
[71] Fix | Delete
}
[72] Fix | Delete
}
[73] Fix | Delete
[74] Fix | Delete
$content = $media_tag_processor->get_updated_html();
[75] Fix | Delete
[76] Fix | Delete
// Add the image tag inside the figure tag, and update the image attributes
[77] Fix | Delete
// in order to display the featured image.
[78] Fix | Delete
$media_size_slug = isset( $attributes['mediaSizeSlug'] ) ? $attributes['mediaSizeSlug'] : 'full';
[79] Fix | Delete
$image_tag = '<img class="wp-block-media-text__featured_image">';
[80] Fix | Delete
$content = preg_replace(
[81] Fix | Delete
'/(<figure\s+id="' . preg_quote( $unique_id, '/' ) . '"\s+class="wp-block-media-text__media"\s*>)/',
[82] Fix | Delete
'$1' . $image_tag,
[83] Fix | Delete
$content
[84] Fix | Delete
);
[85] Fix | Delete
[86] Fix | Delete
$image_tag_processor = new WP_HTML_Tag_Processor( $content );
[87] Fix | Delete
if ( $image_tag_processor->next_tag(
[88] Fix | Delete
array(
[89] Fix | Delete
'tag_name' => 'figure',
[90] Fix | Delete
'id' => $unique_id,
[91] Fix | Delete
)
[92] Fix | Delete
) ) {
[93] Fix | Delete
// The ID is only used to ensure that the correct figure tag is selected,
[94] Fix | Delete
// and can now be removed.
[95] Fix | Delete
$image_tag_processor->remove_attribute( 'id' );
[96] Fix | Delete
if ( $image_tag_processor->next_tag(
[97] Fix | Delete
array(
[98] Fix | Delete
'tag_name' => 'img',
[99] Fix | Delete
'class_name' => 'wp-block-media-text__featured_image',
[100] Fix | Delete
)
[101] Fix | Delete
) ) {
[102] Fix | Delete
$image_tag_processor->set_attribute( 'src', esc_url( $current_featured_image ) );
[103] Fix | Delete
$image_tag_processor->set_attribute( 'class', 'wp-image-' . get_post_thumbnail_id() . ' size-' . $media_size_slug );
[104] Fix | Delete
$image_tag_processor->set_attribute( 'alt', trim( strip_tags( get_post_meta( get_post_thumbnail_id(), '_wp_attachment_image_alt', true ) ) ) );
[105] Fix | Delete
if ( $image_fill ) {
[106] Fix | Delete
$image_tag_processor->set_attribute( 'style', 'object-position:' . $focal_point . ';' );
[107] Fix | Delete
}
[108] Fix | Delete
[109] Fix | Delete
$content = $image_tag_processor->get_updated_html();
[110] Fix | Delete
}
[111] Fix | Delete
}
[112] Fix | Delete
[113] Fix | Delete
return $content;
[114] Fix | Delete
}
[115] Fix | Delete
[116] Fix | Delete
/**
[117] Fix | Delete
* Registers the `core/media-text` block renderer on server.
[118] Fix | Delete
*
[119] Fix | Delete
* @since 6.6.0
[120] Fix | Delete
*/
[121] Fix | Delete
function register_block_core_media_text() {
[122] Fix | Delete
register_block_type_from_metadata(
[123] Fix | Delete
__DIR__ . '/media-text',
[124] Fix | Delete
array(
[125] Fix | Delete
'render_callback' => 'render_block_core_media_text',
[126] Fix | Delete
)
[127] Fix | Delete
);
[128] Fix | Delete
}
[129] Fix | Delete
add_action( 'init', 'register_block_core_media_text' );
[130] Fix | Delete
[131] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function