wppaste
WordPress

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.

Properties · 1

$post_typestringprotected
Post type.

Methods · 23

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.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 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.