WP_REST_Templates_Controller
- Since
- 5.8.0
- Source
wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php:17
Base Templates REST API Controller.
Compatibility
- WordPress
- since 5.8.0
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0).
Hooks and filters fired · 4
Every hook that fires from inside WP_REST_Templates_Controller, in the order it appears in the class, grouped by the method that fires it.
WP_REST_Templates_Controller::update_item()
- do_action( rest_after_insert_{$this->post_type} )action line 419
WP_REST_Templates_Controller::create_item()
- do_action( rest_after_insert_{$this->post_type} )action line 479
Properties · 1
$post_typestringprotected- Post type.
Methods · 23
- __construct()Constructor.
- register_routes()Registers the controllers routes.
- get_template_fallback()Returns the fallback template for the given slug.
- permissions_check()Checks if the user has permissions to make the request.
- _sanitize_template_id()Requesting this endpoint for a template like 'twentytwentytwo//home' requires using a path like /wp/v2/templates/twentytwentytwo//home. There are special cases when WordPress routing corrects the name to contain only a single slash like 'twentytwentytwo/home'.
- get_items_permissions_check()Checks if a given request has access to read templates.
- get_items()Returns a list of templates.
- get_item_permissions_check()Checks if a given request has access to read a single template.
- get_item()Returns the given template
- update_item_permissions_check()Checks if a given request has access to write a single template.
- update_item()Updates a single template.
- create_item_permissions_check()Checks if a given request has access to create a template.
- create_item()Creates a single template.
- delete_item_permissions_check()Checks if a given request has access to delete a single template.
- delete_item()Deletes a single template.
- prepare_item_for_database()Prepares a single template for create or update.
- prepare_item_for_response()Prepare a single template output for response
- get_wp_templates_original_source_field()Returns the source from where the template originally comes from.
- get_wp_templates_author_text_field()Returns a human readable text for the author of the template.
- prepare_links()Prepares links for the request.
- get_available_actions()Get the link relations available for the post and current user.
- get_collection_params()Retrieves the query params for the posts collection.
- get_item_schema()Retrieves the block type' schema, conforming to JSON Schema.
Source code
class WP_REST_Templates_Controller extends WP_REST_Controller { /** * Post type. * * @since 5.8.0 * @var string */ protected $post_type; /** * Constructor. * * @since 5.8.0 * * @param string $post_type Post type. */ public function __construct( $post_type ) { $this->post_type = $post_type; $obj = get_post_type_object( $post_type ); $this->rest_base = ! empty( $obj->rest_base ) ? $obj->rest_base : $obj->name; $this->namespace = ! empty( $obj->rest_namespace ) ? $obj->rest_namespace : 'wp/v2'; } /** * Registers the controllers routes. * * @since 5.8.0 * @since 6.1.0 Endpoint for fallback template content. */ public function register_routes() { // Lists all templates. register_rest_route( $this->namespace, '/' . $this->rest_base, array( array( 'methods' => WP_REST_Server::READABLE, 'callback' => array( $this, 'get_items' ), 'permission_callback' => array( $this, 'get_items_permissions_check' ), 'args' => $this->get_collection_params(), ), array( 'methods' => WP_REST_Server::CREATABLE, 'callback' => array( $this, 'create_item' ), 'permission_callback' => array( $this, 'create_item_permissions_check' ), 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), ), 'schema' => array( $this, 'get_public_item_schema' ), ) ); // 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' ), 'type' => 'string', 'required' => true, ), 'is_custom' => array( 'description' => __( 'Indicates if a template is custom or part of the template hierarchy' ), 'type' => 'boolean', ), 'template_prefix' => array( 'description' => __( 'The template prefix for the created template. This is used to extract the main template type, e.g. in `taxonomy-books` extracts the `taxonomy`' ), 'type' => 'string', ), ), ), ) );Changelog
Introduced in 5.8.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.8.8 tag, from
src/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.