-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move default template types and template part areas to REST API
- Loading branch information
Showing
4 changed files
with
74 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
/** | ||
* Adds the default template part areas to the REST API index. | ||
* | ||
* This function exposes the default template part areas through the WordPress REST API. | ||
* Note: This function backports into the wp-includes/rest-api/class-wp-rest-server.php file. | ||
* | ||
* @param WP_REST_Response $response REST API response. | ||
* @return WP_REST_Response Modified REST API response with default template part areas. | ||
*/ | ||
function gutenberg_add_default_template_part_areas_to_index( WP_REST_Response $response ) { | ||
$response->data['defaultTemplatePartAreas'] = get_allowed_block_template_part_areas(); | ||
return $response; | ||
} | ||
|
||
add_action( 'rest_index', 'gutenberg_add_default_template_part_areas_to_index' ); | ||
|
||
/** | ||
* Adds the default template types to the REST API index. | ||
* | ||
* This function exposes the default template types through the WordPress REST API. | ||
* Note: This function backports into the wp-includes/rest-api/class-wp-rest-server.php file. | ||
* | ||
* @param WP_REST_Response $response REST API response. | ||
* @return WP_REST_Response Modified REST API response with default template part areas. | ||
*/ | ||
function gutenberg_add_default_template_types_to_index( WP_REST_Response $response ) { | ||
$indexed_template_types = array(); | ||
foreach ( get_default_block_template_types() as $slug => $template_type ) { | ||
$template_type['slug'] = (string) $slug; | ||
$indexed_template_types[] = $template_type; | ||
} | ||
|
||
$response->data['defaultTemplateTypes'] = indexed_template_types(); | ||
return $response; | ||
} | ||
|
||
add_action( 'rest_index', 'gutenberg_add_default_template_types_to_index' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters