PluginProbe
پینوا | Pinova / trunk
پینوا | Pinova vtrunk
pinova / src / API / RestAPI.php

RestAPI.php in پینوا | Pinova trunk, at src/API/RestAPI.php

37 lines 699 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Pinova\API;
4
5 use WP_REST_Request;
6
7 abstract class RestAPI {
8
9 public function __construct() {
10 add_action( 'rest_api_init', [ $this, 'register_routes' ] );
11 }
12
13 abstract public function register_routes();
14
15 public function permission_callback( WP_REST_Request $request ): bool {
16 return true;
17 }
18
19 /**
20 * @param bool $success
21 * @param string|null $message
22 * @param array $data
23 *
24 * @return no-return
25 */
26 public static function response( bool $success, ?string $message = null, array $data = [] ) {
27
28 echo wp_json_encode( [
29 'success' => $success,
30 'message' => $message,
31 'data' => $data,
32 ] );
33
34 die();
35 }
36
37 }