Edit File by line
/home/zeestwma/redstone.../wp-inclu.../blocks
File: cover.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Server-side rendering of the `core/cover` block.
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
/**
[7] Fix | Delete
* Renders the `core/cover` block on server.
[8] Fix | Delete
*
[9] Fix | Delete
* @since 6.0.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 cover block markup, if useFeaturedImage is true.
[15] Fix | Delete
*/
[16] Fix | Delete
function render_block_core_cover( $attributes, $content ) {
[17] Fix | Delete
if ( 'image' !== $attributes['backgroundType'] || false === $attributes['useFeaturedImage'] ) {
[18] Fix | Delete
return $content;
[19] Fix | Delete
}
[20] Fix | Delete
[21] Fix | Delete
$object_position = isset( $attributes['focalPoint'] )
[22] Fix | Delete
? round( $attributes['focalPoint']['x'] * 100 ) . '% ' . round( $attributes['focalPoint']['y'] * 100 ) . '%'
[23] Fix | Delete
: null;
[24] Fix | Delete
[25] Fix | Delete
if ( ! ( $attributes['hasParallax'] || $attributes['isRepeated'] ) ) {
[26] Fix | Delete
$attr = array(
[27] Fix | Delete
'class' => 'wp-block-cover__image-background',
[28] Fix | Delete
'data-object-fit' => 'cover',
[29] Fix | Delete
);
[30] Fix | Delete
[31] Fix | Delete
if ( $object_position ) {
[32] Fix | Delete
$attr['data-object-position'] = $object_position;
[33] Fix | Delete
$attr['style'] = 'object-position:' . $object_position . ';';
[34] Fix | Delete
}
[35] Fix | Delete
[36] Fix | Delete
$image = get_the_post_thumbnail( null, $attributes['sizeSlug'] ?? 'post-thumbnail', $attr );
[37] Fix | Delete
} else {
[38] Fix | Delete
if ( in_the_loop() ) {
[39] Fix | Delete
update_post_thumbnail_cache();
[40] Fix | Delete
}
[41] Fix | Delete
$current_featured_image = get_the_post_thumbnail_url( null, $attributes['sizeSlug'] ?? null );
[42] Fix | Delete
if ( ! $current_featured_image ) {
[43] Fix | Delete
return $content;
[44] Fix | Delete
}
[45] Fix | Delete
[46] Fix | Delete
$current_thumbnail_id = get_post_thumbnail_id();
[47] Fix | Delete
[48] Fix | Delete
$processor = new WP_HTML_Tag_Processor( '<div></div>' );
[49] Fix | Delete
$processor->next_tag();
[50] Fix | Delete
[51] Fix | Delete
$current_alt = trim( strip_tags( get_post_meta( $current_thumbnail_id, '_wp_attachment_image_alt', true ) ) );
[52] Fix | Delete
if ( $current_alt ) {
[53] Fix | Delete
$processor->set_attribute( 'role', 'img' );
[54] Fix | Delete
$processor->set_attribute( 'aria-label', $current_alt );
[55] Fix | Delete
}
[56] Fix | Delete
[57] Fix | Delete
$processor->add_class( 'wp-block-cover__image-background' );
[58] Fix | Delete
$processor->add_class( 'wp-image-' . $current_thumbnail_id );
[59] Fix | Delete
if ( $attributes['hasParallax'] ) {
[60] Fix | Delete
$processor->add_class( 'has-parallax' );
[61] Fix | Delete
}
[62] Fix | Delete
if ( $attributes['isRepeated'] ) {
[63] Fix | Delete
$processor->add_class( 'is-repeated' );
[64] Fix | Delete
}
[65] Fix | Delete
[66] Fix | Delete
$styles = 'background-position:' . ( $object_position ?? '50% 50%' ) . ';';
[67] Fix | Delete
$styles .= 'background-image:url(' . esc_url( $current_featured_image ) . ');';
[68] Fix | Delete
$processor->set_attribute( 'style', $styles );
[69] Fix | Delete
[70] Fix | Delete
$image = $processor->get_updated_html();
[71] Fix | Delete
}
[72] Fix | Delete
[73] Fix | Delete
/*
[74] Fix | Delete
* Inserts the featured image between the (1st) cover 'background' `span` and 'inner_container' `div`,
[75] Fix | Delete
* and removes eventual whitespace characters between the two (typically introduced at template level)
[76] Fix | Delete
*/
[77] Fix | Delete
$inner_container_start = '/<div\b[^>]+wp-block-cover__inner-container[\s|"][^>]*>/U';
[78] Fix | Delete
if ( 1 === preg_match( $inner_container_start, $content, $matches, PREG_OFFSET_CAPTURE ) ) {
[79] Fix | Delete
$offset = $matches[0][1];
[80] Fix | Delete
$content = substr( $content, 0, $offset ) . $image . substr( $content, $offset );
[81] Fix | Delete
}
[82] Fix | Delete
[83] Fix | Delete
return $content;
[84] Fix | Delete
}
[85] Fix | Delete
[86] Fix | Delete
/**
[87] Fix | Delete
* Registers the `core/cover` block renderer on server.
[88] Fix | Delete
*
[89] Fix | Delete
* @since 6.0.0
[90] Fix | Delete
*/
[91] Fix | Delete
function register_block_core_cover() {
[92] Fix | Delete
register_block_type_from_metadata(
[93] Fix | Delete
__DIR__ . '/cover',
[94] Fix | Delete
array(
[95] Fix | Delete
'render_callback' => 'render_block_core_cover',
[96] Fix | Delete
)
[97] Fix | Delete
);
[98] Fix | Delete
}
[99] Fix | Delete
add_action( 'init', 'register_block_core_cover' );
[100] Fix | Delete
[101] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function