Skip to content

Commit

Permalink
Add auto_insert field to REST API response
Browse files Browse the repository at this point in the history
  • Loading branch information
ockham committed Jul 26, 2023
1 parent 071b7f2 commit ca1bafc
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions lib/experimental/auto-inserting-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,23 +245,11 @@ function gutenberg_serialize_blocks( $blocks ) {
return implode( '', array_map( 'gutenberg_serialize_block', $blocks ) );
}

/**
* Filterable version of `serialize_blocks()`.
*
* This function is identical to `serialize_blocks()`, except that it applies
* the `gutenberg_serialize_block` filter to each block before it is serialized.
*
* @see serialize_blocks()
*/
function gutenberg_register_auto_insert_rest_field() {

Check failure on line 248 in lib/experimental/auto-inserting-blocks.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Missing doc comment for function gutenberg_register_auto_insert_rest_field()
register_rest_field(
'block-type',
'autoinsert',
'auto_insert',
array(
'get_callback' => function( $data ) {
var_dump( $data );
return 'patata';
},
'schema' => array(

Check warning on line 253 in lib/experimental/auto-inserting-blocks.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Array double arrow not aligned correctly; expected 1 space(s) between "'schema'" and double arrow, but found 7.
'description' => __( 'Auto Insert.', 'default' ),
'type' => 'string',
Expand All @@ -270,3 +258,19 @@ function gutenberg_register_auto_insert_rest_field() {
);
}
add_action( 'rest_api_init', 'gutenberg_register_auto_insert_rest_field' );

/**
* Add the `auto_insert` value into the API response.
*
* @since 6.4.0 Added 'auto_insert' property.
*
* @param WP_REST_Response $response The response object.
* @param WP_Block_Type $block_type The block type object.

Check failure on line 268 in lib/experimental/auto-inserting-blocks.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Spaces must be used for mid-line alignment; tabs are not allowed
*/
function filter_block_type_response( $response, $block_type ) {

Check failure on line 270 in lib/experimental/auto-inserting-blocks.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

The "filter_block_type_response()" function should be guarded against redeclaration.

Check warning on line 270 in lib/experimental/auto-inserting-blocks.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Unused function parameter $block_type.
$data = $response->get_data();
$data['auto_insert'] = 'Test';
$response->set_data( $data );
return $response;
}
add_filter( 'rest_prepare_block_type', 'filter_block_type_response', 10, 2 );

0 comments on commit ca1bafc

Please sign in to comment.