Changeset 54132
- Timestamp:
- 09/12/2022 01:12:21 PM (2 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/blocks.php
r53892 r54132 236 236 * @since 5.7.0 Added support for `textdomain` field and i18n handling for all translatable fields. 237 237 * @since 5.9.0 Added support for `variations` and `viewScript` fields. 238 * @since 6.1.0 Added support for `render` field. 238 239 * 239 240 * @param string $file_or_folder Path to the JSON file with metadata definition for … … 344 345 'style' 345 346 ); 347 } 348 349 if ( ! empty( $metadata['render'] ) ) { 350 $template_path = wp_normalize_path( 351 realpath( 352 dirname( $metadata['file'] ) . '/' . 353 remove_block_asset_path_prefix( $metadata['render'] ) 354 ) 355 ); 356 if ( file_exists( $template_path ) ) { 357 /** 358 * Renders the block on the server. 359 * 360 * @since 6.1.0 361 * 362 * @param array $attributes Block attributes. 363 * @param string $content Block default content. 364 * @param WP_Block $block Block instance. 365 * 366 * @return string Returns the block content. 367 */ 368 $settings['render_callback'] = function( $attributes, $content, $block ) use ( $template_path ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable 369 ob_start(); 370 require $template_path; 371 return ob_get_clean(); 372 }; 373 } 346 374 } 347 375 -
trunk/tests/phpunit/data/blocks/notice/block.json
r53718 r54132 25 25 "attributes": { 26 26 "message": { 27 "type": "string", 28 "source": "html", 29 "selector": ".message" 27 "type": "string" 30 28 } 31 29 }, … … 62 60 "viewScript": "tests-notice-view-script", 63 61 "editorStyle": "tests-notice-editor-style", 64 "style": "tests-notice-style" 62 "style": "tests-notice-style", 63 "render": "file:./render.php" 65 64 } -
trunk/tests/phpunit/tests/blocks/register.php
r53858 r54132 390 390 array( 391 391 'message' => array( 392 'type' => 'string', 393 'source' => 'html', 394 'selector' => '.message', 392 'type' => 'string', 395 393 ), 396 394 'lock' => array( 'type' => 'object' ), … … 456 454 wp_normalize_path( wp_styles()->get_data( 'unit-tests-test-block-style', 'path' ) ) 457 455 ); 456 457 // @ticket 53148 458 $this->assertIsCallable( $result->render_callback ); 458 459 } 459 460 -
trunk/tests/phpunit/tests/blocks/render.php
r53157 r54132 48 48 $registry->unregister( 'core/dynamic' ); 49 49 } 50 if ( $registry->is_registered( 'tests/notice' ) ) { 51 $registry->unregister( 'tests/notice' ); 52 } 50 53 51 54 parent::tear_down(); … … 237 240 ); 238 241 } 242 243 /** 244 * @ticket 53148 245 */ 246 public function test_render_field_in_block_json() { 247 $result = register_block_type( 248 DIR_TESTDATA . '/blocks/notice' 249 ); 250 251 $actual_content = do_blocks( '<!-- wp:tests/notice {"message":"Hello from the test"} --><!-- /wp:tests/notice -->' ); 252 $this->assertSame( '<p class="wp-block-tests-notice">Hello from the test</p>', trim( $actual_content ) ); 253 } 254 239 255 240 256 /**
Note: See TracChangeset
for help on using the changeset viewer.