diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-09-19 04:51:18 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-09-19 04:51:18 +0000 |
commit | 0e41b5d52fdc6af6442816b5f465c9db9f84e126 (patch) | |
tree | e139a90049b158d4eed892d1662ee7f5c358fa31 /wp-includes/blocks/file.php | |
parent | Adding upstream version 6.5.5+dfsg1. (diff) | |
download | wordpress-upstream/6.6.1+dfsg1.tar.xz wordpress-upstream/6.6.1+dfsg1.zip |
Adding upstream version 6.6.1+dfsg1.upstream/6.6.1+dfsg1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'wp-includes/blocks/file.php')
-rw-r--r-- | wp-includes/blocks/file.php | 38 |
1 files changed, 17 insertions, 21 deletions
diff --git a/wp-includes/blocks/file.php b/wp-includes/blocks/file.php index ba0343a..87910f0 100644 --- a/wp-includes/blocks/file.php +++ b/wp-includes/blocks/file.php @@ -8,6 +8,8 @@ /** * When the `core/file` block is rendering, check if we need to enqueue the `wp-block-file-view` script. * + * @since 5.8.0 + * * @param array $attributes The block attributes. * @param string $content The block content. * @param WP_Block $block The parsed block. @@ -15,27 +17,6 @@ * @return string Returns the block content. */ function render_block_core_file( $attributes, $content ) { - // Update object's aria-label attribute if present in block HTML. - // Match an aria-label attribute from an object tag. - $pattern = '@<object.+(?<attribute>aria-label="(?<filename>[^"]+)?")@i'; - $content = preg_replace_callback( - $pattern, - static function ( $matches ) { - $filename = ! empty( $matches['filename'] ) ? $matches['filename'] : ''; - $has_filename = ! empty( $filename ) && 'PDF embed' !== $filename; - $label = $has_filename ? - sprintf( - /* translators: %s: filename. */ - __( 'Embed of %s.' ), - $filename - ) - : __( 'PDF embed' ); - - return str_replace( $matches['attribute'], sprintf( 'aria-label="%s"', $label ), $matches[0] ); - }, - $content - ); - // If it's interactive, enqueue the script module and add the directives. if ( ! empty( $attributes['displayPreview'] ) ) { $suffix = wp_scripts_get_suffix(); @@ -57,6 +38,19 @@ function render_block_core_file( $attributes, $content ) { $processor->next_tag( 'object' ); $processor->set_attribute( 'data-wp-bind--hidden', '!state.hasPdfPreview' ); $processor->set_attribute( 'hidden', true ); + + $filename = $processor->get_attribute( 'aria-label' ); + $has_filename = ! empty( $filename ) && 'PDF embed' !== $filename; + $label = $has_filename ? sprintf( + /* translators: %s: filename. */ + __( 'Embed of %s.' ), + $filename + ) : __( 'PDF embed' ); + + // Update object's aria-label attribute if present in block HTML. + // Match an aria-label attribute from an object tag. + $processor->set_attribute( 'aria-label', $label ); + return $processor->get_updated_html(); } @@ -65,6 +59,8 @@ function render_block_core_file( $attributes, $content ) { /** * Registers the `core/file` block on server. + * + * @since 5.8.0 */ function register_block_core_file() { register_block_type_from_metadata( |