PluginProbe
Timetics – Appointment Booking Calendar & Scheduling / 1.0.0
Timetics – Appointment Booking Calendar & Scheduling v1.0.0
1.0.61 1.0.60 1.0.59 1.0.58 1.0.57 1.0.56 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.2 1.0.20 1.0.21 1.0.22 1.0.23 1.0.24 All 62 releases
timetics / core / settings / api-settings.php

api-settings.php in Timetics – Appointment Booking Calendar & Scheduling 1.0.0, at core/settings/api-settings.php

99 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Class Api Settings
4 *
5 * @package Timetics
6 */
7 namespace Timetics\Core\Settings;
8
9 use Timetics\Base\Api;
10 use Timetics\Utils\Singleton;
11
12 class Api_Settings extends Api {
13 use Singleton;
14
15 /**
16 * Store api namespace
17 *
18 * @var string
19 */
20 protected $namespace = 'timetics/v1';
21
22 /**
23 * Store rest base
24 *
25 * @var string
26 */
27 protected $rest_base = 'settings';
28
29 /**
30 * Register rest route
31 *
32 * @return void
33 */
34 public function register_routes() {
35 register_rest_route(
36 $this->namespace, $this->rest_base, [
37 [
38 'methods' => \WP_REST_Server::READABLE,
39 'callback' => [ $this, 'get_settings' ],
40 'permission_callback' => function () {
41 return current_user_can( 'manage_timetics' );
42 },
43 ],
44 [
45 'methods' => \WP_REST_Server::EDITABLE,
46 'callback' => [ $this, 'update_settings' ],
47 'permission_callback' => function () {
48 return current_user_can( 'manage_timetics' );
49 },
50 ],
51 ]
52 );
53 }
54
55 /**
56 * Get settings
57 *
58 * @return JSON
59 */
60 public function get_settings() {
61 $settings = timetics_get_settings();
62
63 $data = [
64 'status_code' => 200,
65 'success' => 1,
66 'message' => __( 'Get all settings', 'timetics' ),
67 'data' => $settings,
68 ];
69
70 return rest_ensure_response( $settings );
71 }
72
73 /**
74 * Update settings
75 *
76 * @param WP_Rest_Request $request
77 *
78 * @return JSON
79 */
80 public function update_settings( $request ) {
81 $options = json_decode( $request->get_body(), true );
82
83 if ( $options ) {
84 foreach ( $options as $key => $value ) {
85 timetics_update_option( $key, $value );
86 }
87 }
88
89 $data = [
90 'status_code' => 200,
91 'success' => 1,
92 'message' => __( 'Settings successfully updated', 'timetics' ),
93 'data' => timetics_get_settings(),
94 ];
95
96 return rest_ensure_response( $data );
97 }
98 }
99