← All changes
|
jetpack_vendor/automattic/jetpack-import/src/endpoints/class-template.php
+61
-0
16.2-beta
→
16.3
View file →
| @@ -1,0 +1,61 @@ | ||
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Templates REST route | |
| 4 | + * | |
| 5 | + * @package automattic/jetpack-import | |
| 6 | + */ | |
| 7 | + | |
| 8 | +namespace Automattic\Jetpack\Import\Endpoints; | |
| 9 | + | |
| 10 | +use WP_Error; | |
| 11 | +use WP_REST_Request; | |
| 12 | +use WP_REST_Response; | |
| 13 | + | |
| 14 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 15 | + exit( 0 ); | |
| 16 | +} | |
| 17 | + | |
| 18 | +/** | |
| 19 | + * Class Template | |
| 20 | + */ | |
| 21 | +class Template extends \WP_REST_Templates_Controller { | |
| 22 | + | |
| 23 | + /** | |
| 24 | + * Base class | |
| 25 | + */ | |
| 26 | + use Import; | |
| 27 | + | |
| 28 | + /** | |
| 29 | + * The Import ID add a new item to the schema. | |
| 30 | + */ | |
| 31 | + use Import_ID; | |
| 32 | + | |
| 33 | + /** | |
| 34 | + * Whether the controller supports batching. | |
| 35 | + * | |
| 36 | + * @var array | |
| 37 | + */ | |
| 38 | + protected $allow_batch = array( 'v1' => true ); | |
| 39 | + | |
| 40 | + /** | |
| 41 | + * Constructor. | |
| 42 | + */ | |
| 43 | + public function __construct() { | |
| 44 | + parent::__construct( 'wp_template' ); | |
| 45 | + } | |
| 46 | + | |
| 47 | + /** | |
| 48 | + * Update the template post. | |
| 49 | + * | |
| 50 | + * @param WP_REST_Request $request Full details about the request. | |
| 51 | + * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. | |
| 52 | + */ | |
| 53 | + public function create_item( $request ) { | |
| 54 | + // Set the WP_IMPORTING constant to prevent sync notifications | |
| 55 | + $this->set_importing(); | |
| 56 | + | |
| 57 | + $response = parent::create_item( $request ); | |
| 58 | + | |
| 59 | + return $this->add_import_id_metadata( $request, $response ); | |
| 60 | + } | |
| 61 | +} | |