Changeset 47360
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-block-renderer-controller.php
r47122 r47360 136 136 } 137 137 $registry = WP_Block_Type_Registry::get_instance(); 138 $block = $registry->get_registered( $request['name'] );139 138 140 if ( null === $ block) {139 if ( null === $registry->get_registered( $request['name'] ) ) { 141 140 return new WP_Error( 142 141 'block_invalid', … … 148 147 } 149 148 149 $attributes = $request->get_param( 'attributes' ); 150 151 // Create an array representation simulating the output of parse_blocks. 152 $block = array( 153 'blockName' => $request['name'], 154 'attrs' => $attributes, 155 'innerHTML' => '', 156 'innerContent' => array(), 157 ); 158 159 // Render using render_block to ensure all relevant filters are used. 150 160 $data = array( 151 'rendered' => $block->render( $request->get_param( 'attributes' )),161 'rendered' => render_block( $block ), 152 162 ); 153 163 -
trunk/tests/phpunit/tests/rest-api/rest-block-renderer-controller.php
r46586 r47360 374 374 } 375 375 376 376 /** 377 * Check filtering block output using the pre_render_block filter. 378 * 379 * @ticket 49387 380 */ 381 public function test_get_item_with_pre_render_block_filter() { 382 wp_set_current_user( self::$user_id ); 383 384 $pre_render_filter = function( $output, $block ) { 385 if ( $block['blockName'] === self::$block_name ) { 386 return '<p>Alternate content.</p>'; 387 } 388 }; 389 add_filter( 'pre_render_block', $pre_render_filter, 10, 2 ); 390 391 $attributes = array( 392 'some_int' => '123', 393 'some_string' => 'foo', 394 'some_array' => array( 1, '2', 3 ), 395 ); 396 397 $request = new WP_REST_Request( 'GET', self::$rest_api_route . self::$block_name ); 398 $request->set_param( 'context', 'edit' ); 399 $request->set_param( 'attributes', $attributes ); 400 $response = rest_get_server()->dispatch( $request ); 401 $this->assertEquals( 200, $response->get_status() ); 402 403 $data = $response->get_data(); 404 $this->assertEquals( '<p>Alternate content.</p>', $data['rendered'] ); 405 406 remove_filter( 'pre_render_block', $pre_render_filter ); 407 } 377 408 378 409 /**
Note: See TracChangeset
for help on using the changeset viewer.