PluginProbe
Timetics – Appointment Booking Calendar & Scheduling / 1.0.16
Timetics – Appointment Booking Calendar & Scheduling v1.0.16
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.16, at core/settings/api-settings.php

226 lines 8.4 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 true;
42 },
43 ],
44 [
45 'methods' => \WP_REST_Server::EDITABLE,
46 'callback' => [$this, 'update_settings'],
47 'permission_callback' => function () {
48 return true;
49 },
50 ],
51 ]
52 );
53
54 register_rest_route(
55 $this->namespace, $this->rest_base . '/business', [
56 [
57 'methods' => \WP_REST_Server::CREATABLE,
58 'callback' => [$this, 'setup_business'],
59 'permission_callback' => function () {
60 return current_user_can( 'manage_options' );
61 },
62 ],
63 ]
64 );
65
66 register_rest_route(
67 $this->namespace, $this->rest_base . '/business/categories', [
68 [
69 'methods' => \WP_REST_Server::READABLE,
70 'callback' => [$this, 'get_busyness_categories'],
71 'permission_callback' => function () {
72 return current_user_can( 'manage_options' );
73 },
74 ],
75 ]
76 );
77 }
78
79 /**
80 * Get settings
81 *
82 * @return JSON
83 */
84 public function get_settings() {
85 $settings = apply_filters( 'timetics_settings', timetics_get_settings() );
86
87 $data = [
88 'status_code' => 200,
89 'success' => 1,
90 'message' => esc_html__( 'Get all settings', 'timetics' ),
91 'data' => $settings,
92 ];
93
94 return rest_ensure_response( $settings );
95 }
96
97 /**
98 * Update settings
99 *
100 * @param WP_Rest_Request $request
101 *
102 * @return JSON
103 */
104 public function update_settings( $request ) {
105 $options = json_decode( $request->get_body(), true );
106
107 /**
108 * Added temporary for leagacy sass. It will remove in future.
109 */
110 $data = [
111 'status_code' => 200,
112 'success' => 1,
113 'message' => esc_html__( 'Settings successfully updated', 'timetics' ),
114 'data' => timetics_get_settings(),
115 ];
116
117 if ( !empty($options['schedule']) && $options['schedule'] && apply_filters('timetics/staff/member/availability', false)) {
118 return rest_ensure_response( apply_filters( 'timetics/admin/staff/error_data', $data, 'availability_update' ) );
119 }
120
121 if ( !empty($options['availability']) && $options['availability'] && apply_filters('timetics/staff/meeting/availability', false)) {
122 return rest_ensure_response( apply_filters( 'timetics/admin/appointment/error_data', $data, 'availability_update' ) );
123 }
124
125 if ( ! empty( $options['custom_fields'] ) && apply_filters( 'timetics/admin/settings/custom_fields', false, $options['custom_fields'] ) ) {
126 return rest_ensure_response( apply_filters( 'timetics/admin/settings/error_data', $data, 'custom_fields', timetics_get_settings() ) );
127 }
128
129 if ( ! empty( $options['paypal_status'] ) && $options['paypal_status'] && apply_filters( 'timetics/admin/settings/paypal', false ) ) {
130 return rest_ensure_response( apply_filters( 'timetics/admin/settings/error_data', $data, 'paypal', timetics_get_settings() ) );
131 }
132
133 if ( ! empty( $options['zoom_client_secret'] ) && $options['zoom_client_secret'] && apply_filters( 'timetics/admin/settings/zoom', false ) ) {
134 return rest_ensure_response( apply_filters( 'timetics/admin/settings/error_data', $data, 'zoom', timetics_get_settings() ) );
135 }
136
137 if ( ! empty( $options['fluentcrm_webhook'] ) && $options['fluentcrm_webhook'] && apply_filters( 'timetics/admin/settings/fluentcrm_webhook', false ) ) {
138 return rest_ensure_response( apply_filters( 'timetics/admin/settings/error_data', $data, 'fluent_crm', timetics_get_settings() ) );
139 }
140
141 if ( ! empty( $options['pabbly_webhook'] ) && $options['pabbly_webhook'] && apply_filters( 'timetics/admin/settings/pabbly_webhook', false ) ) {
142 return rest_ensure_response( apply_filters( 'timetics/admin/settings/error_data', $data, 'pablly', timetics_get_settings() ) );
143 }
144
145 if ( ! empty( $options['zapier_webhook'] ) && $options['zapier_webhook'] && apply_filters( 'timetics/admin/settings/zapier_webhook', false ) ) {
146 return rest_ensure_response( apply_filters( 'timetics/admin/settings/error_data', $data, 'zapier', timetics_get_settings() ) );
147 }
148
149 if (!empty($options['google_app_client_id']) && $options['google_app_client_id'] && apply_filters('timetics/admin/settings/google_calendar', false)) {
150 return rest_ensure_response(apply_filters('timetics/admin/settings/error_data', $data, 'google-calendar', timetics_get_settings()));
151 }
152
153 if ( ! empty( $options['google_app_client_secret'] ) && $options['google_app_client_secret'] && apply_filters( 'timetics/admin/settings/google-calendar', false ) ) {
154 return rest_ensure_response( apply_filters( 'timetics/admin/settings/error_data', $data, 'google-calendar', timetics_get_settings() ) );
155 }
156
157 if ( ! empty( $options['outlook_calendar'] ) && $options['outlook_calendar'] && apply_filters( 'timetics/admin/settings/outlook_calendar', false ) ) {
158 return rest_ensure_response( apply_filters( 'timetics/admin/settings/error_data', $data, 'outlook', timetics_get_settings() ) );
159 }
160
161 if ( ! empty( $options['apple_calendar'] ) && $options['apple_calendar'] && apply_filters( 'timetics/admin/settings/apple_calendar', false ) ) {
162 return rest_ensure_response( apply_filters( 'timetics/admin/settings/error_data', $data, 'paypal', timetics_get_settings() ) );
163 }
164
165 if (!empty($options['twillo_message']) && $options['twillo_message'] && apply_filters('timetics/admin/settings/twillo_messaging', false)) {
166 return rest_ensure_response(apply_filters('timetics/admin/settings/error_data', $data, 'twillo_messaging', timetics_get_settings()));
167 }
168
169 if ( $options ) {
170 foreach ( $options as $key => $value ) {
171 timetics_update_option( $key, $value );
172 }
173 }
174
175 $data['data'] = timetics_get_settings();
176
177 return rest_ensure_response( $data );
178 }
179
180 /**
181 * Business setup
182 *
183 * @param WP_Rest_Request $request
184 *
185 * @return void
186 */
187 public function setup_business( $request ) {
188 $data = json_decode( $request->get_body(), true );
189
190 $email = ! empty( $data['email'] ) ? $data['email'] : '';
191
192 $body = array(
193 'email' => $email,
194 );
195
196 $response_user = wp_remote_post( 'https://arraytics.com/?fluentcrm=1&route=contact&hash=0d9cd3d1-514d-4e1a-9147-09dfd5f9e997', ['body' => $body] );
197
198 $response = [
199 'status' => 200,
200 'success' => 1,
201 'message' => __( 'Successfully updated business', 'timetics' ),
202 ];
203
204 return rest_ensure_response( $response );
205 }
206
207 /**
208 * Get busyness categories
209 *
210 * @param WP_Rest_Request $request
211 *
212 * @return JSON
213 */
214 public function get_busyness_categories( $request ) {
215 $busyness_categories = timetics_get_busyness_categories();
216
217 $response = [
218 'success' => 1,
219 'status_code' => 200,
220 'data' => $busyness_categories,
221 ];
222
223 return rest_ensure_response( $response );
224 }
225 }
226