Edit File by line
/home/zeestwma/redstone.../wp-inclu.../blocks
File: video.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Server-side rendering of the `core/video` block.
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
/**
[7] Fix | Delete
* Renders the `core/video` block on the server to supply the width and height attributes from the attachment metadata.
[8] Fix | Delete
*
[9] Fix | Delete
* @since 6.9.0
[10] Fix | Delete
*
[11] Fix | Delete
* @phpstan-param array{ "id"?: positive-int } $attributes
[12] Fix | Delete
*
[13] Fix | Delete
* @param array $attributes The block attributes.
[14] Fix | Delete
* @param string $content The block content.
[15] Fix | Delete
* @return string The block content with the dimensions added.
[16] Fix | Delete
*/
[17] Fix | Delete
function render_block_core_video( array $attributes, string $content ): string {
[18] Fix | Delete
// if the content lacks any video tag, abort.
[19] Fix | Delete
if ( ! str_contains( $content, '<video' ) ) {
[20] Fix | Delete
return $content;
[21] Fix | Delete
}
[22] Fix | Delete
[23] Fix | Delete
// If the 'id' attribute is not populated for a video attachment, abort.
[24] Fix | Delete
if (
[25] Fix | Delete
! isset( $attributes['id'] ) ||
[26] Fix | Delete
! is_int( $attributes['id'] ) ||
[27] Fix | Delete
$attributes['id'] <= 0
[28] Fix | Delete
) {
[29] Fix | Delete
return $content;
[30] Fix | Delete
}
[31] Fix | Delete
[32] Fix | Delete
// If the 'id' attribute wasn't for an attachment, abort.
[33] Fix | Delete
if ( get_post_type( $attributes['id'] ) !== 'attachment' ) {
[34] Fix | Delete
return $content;
[35] Fix | Delete
}
[36] Fix | Delete
[37] Fix | Delete
// Get the width and height metadata for the video, and abort if absent or invalid.
[38] Fix | Delete
$metadata = wp_get_attachment_metadata( $attributes['id'] );
[39] Fix | Delete
if (
[40] Fix | Delete
! isset( $metadata['width'], $metadata['height'] ) ||
[41] Fix | Delete
! ( is_int( $metadata['width'] ) && is_int( $metadata['height'] ) ) ||
[42] Fix | Delete
! ( $metadata['width'] > 0 && $metadata['height'] > 0 )
[43] Fix | Delete
) {
[44] Fix | Delete
return $content;
[45] Fix | Delete
}
[46] Fix | Delete
[47] Fix | Delete
// Locate the VIDEO tag to add the dimensions.
[48] Fix | Delete
$p = new WP_HTML_Tag_Processor( $content );
[49] Fix | Delete
if ( ! $p->next_tag( array( 'tag_name' => 'VIDEO' ) ) ) {
[50] Fix | Delete
return $content;
[51] Fix | Delete
}
[52] Fix | Delete
[53] Fix | Delete
$p->set_attribute( 'width', (string) $metadata['width'] );
[54] Fix | Delete
$p->set_attribute( 'height', (string) $metadata['height'] );
[55] Fix | Delete
[56] Fix | Delete
/*
[57] Fix | Delete
* The aspect-ratio style is needed due to an issue with the CSS spec: <https://github.com/w3c/csswg-drafts/issues/7524>.
[58] Fix | Delete
* Note that a style rule using attr() like the following cannot currently be used:
[59] Fix | Delete
*
[60] Fix | Delete
* .wp-block-video video[width][height] {
[61] Fix | Delete
* aspect-ratio: attr(width type(<number>)) / attr(height type(<number>));
[62] Fix | Delete
* }
[63] Fix | Delete
*
[64] Fix | Delete
* This is because this attr() is yet only implemented in Chromium: <https://caniuse.com/css3-attr>.
[65] Fix | Delete
*/
[66] Fix | Delete
$style = $p->get_attribute( 'style' );
[67] Fix | Delete
if ( ! is_string( $style ) ) {
[68] Fix | Delete
$style = '';
[69] Fix | Delete
}
[70] Fix | Delete
$aspect_ratio_style = sprintf( 'aspect-ratio: %d / %d;', $metadata['width'], $metadata['height'] );
[71] Fix | Delete
$p->set_attribute( 'style', $aspect_ratio_style . $style );
[72] Fix | Delete
[73] Fix | Delete
return $p->get_updated_html();
[74] Fix | Delete
}
[75] Fix | Delete
[76] Fix | Delete
/**
[77] Fix | Delete
* Registers the `core/video` block on server.
[78] Fix | Delete
*
[79] Fix | Delete
* @since 6.9.0
[80] Fix | Delete
*/
[81] Fix | Delete
function register_block_core_video(): void {
[82] Fix | Delete
register_block_type_from_metadata(
[83] Fix | Delete
__DIR__ . '/video',
[84] Fix | Delete
array(
[85] Fix | Delete
'render_callback' => 'render_block_core_video',
[86] Fix | Delete
)
[87] Fix | Delete
);
[88] Fix | Delete
}
[89] Fix | Delete
add_action( 'init', 'register_block_core_video' );
[90] Fix | Delete
[91] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function