← All changes
|
jetpack_vendor/automattic/jetpack-import/src/endpoints/class-menu.php
+27
-9
12.0.3
→
16.3
View file →
| @@ -6,8 +6,16 @@ | ||
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | namespace Automattic\Jetpack\Import\Endpoints; |
| 9 | 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 | + | |
| 10 | 18 | /** |
| 11 | 19 | * Class Menu |
| 12 | 20 | */ |
| 13 | 21 | class Menu extends \WP_REST_Menus_Controller { |
| @@ -12,11 +20,16 @@ | ||
| 12 | 20 | */ |
| 13 | 21 | class Menu extends \WP_REST_Menus_Controller { |
| 14 | 22 | |
| 15 | 23 | /** |
| 24 | + * Base class | |
| 25 | + */ | |
| 26 | + use Import; | |
| 27 | + | |
| 28 | + /** | |
| 16 | 29 | * The Import ID add a new item to the schema. |
| 17 | 30 | */ |
| 18 | - use Import; | |
| 31 | + use Import_ID; | |
| 19 | 32 | |
| 20 | 33 | /** |
| 21 | 34 | * Whether the controller supports batching. Default true. |
| 22 | 35 | * |
| @@ -34,16 +47,21 @@ | ||
| 34 | 47 | $this->import_id_meta_type = 'term'; |
| 35 | 48 | } |
| 36 | 49 | |
| 37 | 50 | /** |
| 38 | - * Registers the routes for the objects of the controller. | |
| 51 | + * Creates a single menu. | |
| 39 | 52 | * |
| 40 | - * @see WP_REST_Terms_Controller::register_rest_route() | |
| 53 | + * @param WP_REST_Request $request Full details about the request. | |
| 54 | + * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. | |
| 41 | 55 | */ |
| 42 | - public function register_routes() { | |
| 43 | - register_rest_route( | |
| 44 | - self::$rest_namespace, | |
| 45 | - '/menus', | |
| 46 | - $this->get_route_options() | |
| 47 | - ); | |
| 56 | + public function create_item( $request ) { | |
| 57 | + // Set the WP_IMPORTING constant to prevent sync notifications | |
| 58 | + $this->set_importing(); | |
| 59 | + | |
| 60 | + $response = parent::create_item( $request ); | |
| 61 | + | |
| 62 | + // Ensure that the HTTP status is a valid one. | |
| 63 | + $response = $this->ensure_http_status( $response, 'menu_exists', 409 ); | |
| 64 | + | |
| 65 | + return $this->add_import_id_metadata( $request, $response ); | |
| 48 | 66 | } |
| 49 | 67 | } |