PluginProbe
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 3.4.1
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v3.4.1
4.7.2 4.7.1 4.7.0 4.6.6 4.6.5 4.6.4 4.6.3 4.6.2 4.6.1 4.6.0 4.5.1 4.5.0 4.4.2 4.4.1 4.4.0 4.3.3 4.3.2 4.3.1 4.3.0 4.2.3 4.2.2 4.2.1 1.0.3 1.0.4 1.0.5 All 281 releases
surecart / app / src / Rest / ReturnItemsRestServiceProvider.php
ReturnItemsRestServiceProvider.php
83 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace SureCart\Rest;
4
5 use SureCart\Controllers\Rest\ReturnItemsController;
6
7 /**
8 * Service provider for ReturnItems rest requests
9 */
10 class ReturnItemsRestServiceProvider extends RestServiceProvider implements RestServiceInterface {
11 /**
12 * Endpoint
13 *
14 * @var string
15 */
16 protected $endpoint = 'return_items';
17
18 /**
19 * Rest Controller
20 *
21 * @var string
22 */
23 protected $controller = ReturnItemsController::class;
24
25 /**
26 * Methods allowed for the model.
27 *
28 * @var array
29 */
30 protected $methods = [ 'index', 'find' ];
31
32 /**
33 * Get our samples schema for a post
34 *
35 * @return array The sample schema for a post
36 */
37 public function get_item_schema() {
38 if ( $this->schema ) {
39 // Since WordPress 5.3, the schema can be cached in the $schema property.
40 return $this->schema;
41 }
42
43 $this->schema = [
44 // This tells the spec of JSON Schema we are using which is draft 4.
45 '$schema' => 'http://json-schema.org/draft-04/schema#',
46 // The title property marks the identity of the resource.
47 'title' => $this->endpoint,
48 'type' => 'object',
49 // In JSON Schema you can specify object properties in the properties attribute.
50 'properties' => [
51 'id' => [
52 'description' => esc_html__( 'Unique identifier for the object.', 'surecart' ),
53 'type' => 'string',
54 'context' => [ 'view', 'edit', 'embed' ],
55 'readonly' => true,
56 ],
57 ],
58 ];
59
60 return $this->schema;
61 }
62
63 /**
64 * Who can read return items
65 *
66 * @param \WP_REST_Request $request Rest Request.
67 * @return true|\WP_Error True if the request has access to read return items, WP_Error object otherwise.
68 */
69 public function get_items_permissions_check( $request ) {
70 return current_user_can( 'read_sc_orders' );
71 }
72
73 /**
74 * Who can read a return item
75 *
76 * @param \WP_REST_Request $request Rest Request.
77 * @return true|\WP_Error True if the request has access to read return item, WP_Error object otherwise.
78 */
79 public function get_item_permissions_check( $request ) {
80 return current_user_can( 'read_sc_orders' );
81 }
82 }
83