← All changes
|
src/editor/components/block-attributes/class-block-attributes.php
+17
-2
7.1.0
→
7.2.0
View file →
| @@ -40,8 +40,16 @@ | ||
| 40 | 40 | */ |
| 41 | 41 | public const VOICE_ATTRIBUTE = 'beyondwordsVoiceId'; |
| 42 | 42 | |
| 43 | 43 | /** |
| 44 | + * The block whose `<audio>` tag always gets the audio data attribute — | |
| 45 | + * every core/audio block has a file, so there is nothing to opt into. | |
| 46 | + * | |
| 47 | + * @since 7.2.0 | |
| 48 | + */ | |
| 49 | + public const AUDIO_BLOCK_NAME = 'core/audio'; | |
| 50 | + | |
| 51 | + /** | |
| 44 | 52 | * Init. |
| 45 | 53 | * |
| 46 | 54 | * @since 4.0.0 |
| 47 | 55 | * @since 6.0.0 Make static and remove renderBlock registration. |
| @@ -142,14 +150,15 @@ | ||
| 142 | 150 | return $args; |
| 143 | 151 | } |
| 144 | 152 | |
| 145 | 153 | /** |
| 146 | - * Add the segment-scoped voice data attributes to a rendered block. | |
| 154 | + * Add the segment-scoped voice and audio data attributes to a rendered block. | |
| 147 | 155 | * |
| 148 | 156 | * Not registered in init(): it is added around the API body build only, so |
| 149 | 157 | * front-end output is untouched. |
| 150 | 158 | * |
| 151 | 159 | * @since 7.1.0 |
| 160 | + * @since 7.2.0 Add the audio data attribute to core/audio blocks. | |
| 152 | 161 | * |
| 153 | 162 | * @param string $block_content The rendered block HTML. |
| 154 | 163 | * @param array $block The parsed block. |
| 155 | 164 | */ |
| @@ -159,10 +168,11 @@ | ||
| 159 | 168 | $attrs = ( is_array( $block ) && is_array( $block['attrs'] ?? null ) ) ? $block['attrs'] : []; |
| 160 | 169 | |
| 161 | 170 | $language = self::language_code( self::attribute_value( $attrs, self::LANGUAGE_ATTRIBUTE ) ); |
| 162 | 171 | $voice_id = self::voice_id( self::attribute_value( $attrs, self::VOICE_ATTRIBUTE ) ); |
| 172 | + $is_audio = is_array( $block ) && self::AUDIO_BLOCK_NAME === ( $block['blockName'] ?? '' ); | |
| 163 | 173 | |
| 164 | - if ( '' === $language && '' === $voice_id ) { | |
| 174 | + if ( '' === $language && '' === $voice_id && ! $is_audio ) { | |
| 165 | 175 | return $block_content; |
| 166 | 176 | } |
| 167 | 177 | |
| 168 | 178 | $processor = new \WP_HTML_Tag_Processor( $block_content ); |
| @@ -177,8 +187,13 @@ | ||
| 177 | 187 | } |
| 178 | 188 | |
| 179 | 189 | if ( '' !== $voice_id ) { |
| 180 | 190 | $processor->set_attribute( 'data-beyondwords-voice-id', $voice_id ); |
| 191 | + } | |
| 192 | + | |
| 193 | + // The audio marker belongs on the <audio> tag itself, not the figure wrapping it. | |
| 194 | + if ( $is_audio && $processor->next_tag( [ 'tag_name' => 'AUDIO' ] ) ) { | |
| 195 | + $processor->set_attribute( 'data-beyondwords-audio', 'true' ); | |
| 181 | 196 | } |
| 182 | 197 | |
| 183 | 198 | return $processor->get_updated_html(); |
| 184 | 199 | } |