1 | <?php |
||
17 | class CMB2_REST_Controller_Boxes extends CMB2_REST_Controller { |
||
|
|||
18 | |||
19 | /** |
||
20 | * The base of this controller's route. |
||
21 | * |
||
22 | * @var string |
||
23 | */ |
||
24 | protected $rest_base = 'boxes'; |
||
25 | |||
26 | /** |
||
27 | * The combined $namespace and $rest_base for these routes. |
||
28 | * |
||
29 | * @var string |
||
30 | */ |
||
31 | protected $namespace_base = ''; |
||
32 | |||
33 | /** |
||
34 | * Constructor |
||
35 | * @since 2.2.4 |
||
36 | */ |
||
37 | public function __construct( WP_REST_Server $wp_rest_server ) { |
||
41 | |||
42 | /** |
||
43 | * Register the routes for the objects of the controller. |
||
44 | * |
||
45 | * @since 2.2.4 |
||
46 | */ |
||
47 | public function register_routes() { |
||
48 | |||
49 | // Returns all boxes data. |
||
50 | register_rest_route( $this->namespace, '/' . $this->rest_base, array( |
||
51 | array( |
||
52 | 'methods' => WP_REST_Server::READABLE, |
||
53 | 'callback' => array( $this, 'get_items' ), |
||
54 | 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
||
55 | ), |
||
56 | 'schema' => array( $this, 'get_item_schema' ), |
||
57 | ) ); |
||
58 | |||
59 | // Returns specific box's data. |
||
60 | register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<cmb_id>[\w-]+)', array( |
||
61 | array( |
||
62 | 'methods' => WP_REST_Server::READABLE, |
||
63 | 'callback' => array( $this, 'get_item' ), |
||
64 | 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
||
65 | ), |
||
66 | 'schema' => array( $this, 'get_item_schema' ), |
||
67 | ) ); |
||
68 | } |
||
69 | |||
70 | /** |
||
71 | * Get all public CMB2 boxes. |
||
72 | * |
||
73 | * @since 2.2.4 |
||
74 | * |
||
75 | * @param WP_REST_Request $request Full data about the request. |
||
76 | * @return WP_Error|WP_REST_Response |
||
77 | */ |
||
78 | public function get_items( $request ) { |
||
96 | |||
97 | /** |
||
98 | * Get one CMB2 box from the collection. |
||
99 | * |
||
100 | * @since 2.2.4 |
||
101 | * |
||
102 | * @param WP_REST_Request $request Full data about the request. |
||
103 | * @return WP_Error|WP_REST_Response |
||
104 | */ |
||
105 | public function get_item( $request ) { |
||
114 | |||
115 | /** |
||
116 | * Get a CMB2 box prepared for REST |
||
117 | * |
||
118 | * @since 2.2.4 |
||
119 | * |
||
120 | * @return array |
||
121 | */ |
||
122 | public function get_rest_box() { |
||
153 | |||
154 | /** |
||
155 | * Return an array of contextual links for box/boxes. |
||
156 | * |
||
157 | * @since 2.2.4 |
||
158 | * |
||
159 | * @param CMB2_REST $cmb CMB2_REST object to build links from. |
||
160 | * |
||
161 | * @return array Array of links |
||
162 | */ |
||
163 | protected function prepare_links( $cmb ) { |
||
183 | |||
184 | } |
||
185 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.