Changeset 58187 for trunk/src/wp-includes/blocks/file.php
- Timestamp:
- 05/23/2024 07:37:08 PM (9 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/blocks/file.php
r57619 r58187 9 9 * When the `core/file` block is rendering, check if we need to enqueue the `wp-block-file-view` script. 10 10 * 11 * @since 5.8.0 12 * 11 13 * @param array $attributes The block attributes. 12 14 * @param string $content The block content. … … 16 18 */ 17 19 function render_block_core_file( $attributes, $content ) { 18 // Update object's aria-label attribute if present in block HTML.19 // Match an aria-label attribute from an object tag.20 $pattern = '@<object.+(?<attribute>aria-label="(?<filename>[^"]+)?")@i';21 $content = preg_replace_callback(22 $pattern,23 static function ( $matches ) {24 $filename = ! empty( $matches['filename'] ) ? $matches['filename'] : '';25 $has_filename = ! empty( $filename ) && 'PDF embed' !== $filename;26 $label = $has_filename ?27 sprintf(28 /* translators: %s: filename. */29 __( 'Embed of %s.' ),30 $filename31 )32 : __( 'PDF embed' );33 34 return str_replace( $matches['attribute'], sprintf( 'aria-label="%s"', $label ), $matches[0] );35 },36 $content37 );38 39 20 // If it's interactive, enqueue the script module and add the directives. 40 21 if ( ! empty( $attributes['displayPreview'] ) ) { … … 58 39 $processor->set_attribute( 'data-wp-bind--hidden', '!state.hasPdfPreview' ); 59 40 $processor->set_attribute( 'hidden', true ); 41 42 $filename = $processor->get_attribute( 'aria-label' ); 43 $has_filename = ! empty( $filename ) && 'PDF embed' !== $filename; 44 $label = $has_filename ? sprintf( 45 /* translators: %s: filename. */ 46 __( 'Embed of %s.' ), 47 $filename 48 ) : __( 'PDF embed' ); 49 50 // Update object's aria-label attribute if present in block HTML. 51 // Match an aria-label attribute from an object tag. 52 $processor->set_attribute( 'aria-label', $label ); 53 60 54 return $processor->get_updated_html(); 61 55 } … … 66 60 /** 67 61 * Registers the `core/file` block on server. 62 * 63 * @since 5.8.0 68 64 */ 69 65 function register_block_core_file() {
Note: See TracChangeset
for help on using the changeset viewer.