-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prepare rest endpoint to be extended.
- Loading branch information
1 parent
e71ff47
commit d95917c
Showing
4 changed files
with
79 additions
and
16 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
63 changes: 63 additions & 0 deletions
63
lib/compat/wordpress-6.2/class-gutenberg-rest-templates-controller-6-2.php
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,63 @@ | ||
<?php | ||
/** | ||
* REST API: Gutenberg_REST_Templates_Controller_6_2 class | ||
* | ||
* @package Gutenberg | ||
* @subpackage REST_API | ||
*/ | ||
|
||
/** | ||
* Base Templates REST API Controller. | ||
*/ | ||
class Gutenberg_REST_Templates_Controller_6_2 extends Gutenberg_REST_Templates_Controller { | ||
|
||
/** | ||
* Registers the controllers routes. | ||
* | ||
* @return void | ||
*/ | ||
public function register_routes() { | ||
parent::register_routes(); | ||
// Get fallback template content. | ||
register_rest_route( | ||
$this->namespace, | ||
'/' . $this->rest_base . '/lookup', | ||
array( | ||
array( | ||
'methods' => WP_REST_Server::READABLE, | ||
'callback' => array( $this, 'get_template_fallback' ), | ||
'permission_callback' => array( $this, 'get_item_permissions_check' ), | ||
'args' => array( | ||
'slug' => array( | ||
'description' => __( 'The slug of the template to get the fallback for', 'gutenberg' ), | ||
'type' => 'string', | ||
'required' => true, | ||
), | ||
'is_custom' => array( | ||
'description' => __( 'Indicates if a template is custom or part of the template hierarchy', 'gutenberg' ), | ||
'type' => 'boolean', | ||
), | ||
'template_prefix' => array( | ||
'description' => __( 'The template prefix for the created template. This is used to extract the main template type ex. in `taxonomy-books` we extract the `taxonomy`', 'gutenberg' ), | ||
'type' => 'string', | ||
), | ||
), | ||
), | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* Returns the fallback template for a given slug. | ||
* | ||
* @param WP_REST_Request $request The request instance. | ||
* | ||
* @return WP_REST_Response|WP_Error | ||
*/ | ||
public function get_template_fallback( $request ) { | ||
$hierarchy = get_template_hierarchy( $request['slug'], $request['is_custom'], $request['template_prefix'] ); | ||
$fallback_template = resolve_block_template( $request['slug'], $hierarchy, '' ); | ||
$response = $this->prepare_item_for_response( $fallback_template, $request ); | ||
return rest_ensure_response( $response ); | ||
} | ||
} |
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