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

306 lines 11.5 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\Core\Admin\Hooks;
11 use Timetics\Utils\Singleton;
12
13 class Api_Settings extends Api {
14 use Singleton;
15
16 /**
17 * Store api namespace
18 *
19 * @var string
20 */
21 protected $namespace = 'timetics/v1';
22
23 /**
24 * Store rest base
25 *
26 * @var string
27 */
28 protected $rest_base = 'settings';
29
30 /**
31 * Register rest route
32 *
33 * @return void
34 */
35 public function register_routes() {
36 register_rest_route(
37 $this->namespace, $this->rest_base, [
38 [
39 'methods' => \WP_REST_Server::READABLE,
40 'callback' => [$this, 'get_settings'],
41 'permission_callback' => function () {
42 return true;
43 },
44 ],
45 [
46 'methods' => \WP_REST_Server::EDITABLE,
47 'callback' => [$this, 'update_settings'],
48 'permission_callback' => function () {
49 return current_user_can( 'manage_options' );
50 },
51 ],
52 ]
53 );
54
55 register_rest_route(
56 $this->namespace, $this->rest_base . '/business', [
57 [
58 'methods' => \WP_REST_Server::CREATABLE,
59 'callback' => [$this, 'setup_business'],
60 'permission_callback' => function () {
61 return current_user_can( 'manage_options' );
62 },
63 ],
64 ]
65 );
66
67 register_rest_route(
68 $this->namespace, $this->rest_base . '/business/categories', [
69 [
70 'methods' => \WP_REST_Server::READABLE,
71 'callback' => [$this, 'get_busyness_categories'],
72 'permission_callback' => function () {
73 return current_user_can( 'manage_options' );
74 },
75 ],
76 ]
77 );
78 }
79
80 /**
81 * Get settings
82 *
83 * @return JSON
84 */
85 public function get_settings() {
86 $settings = apply_filters( 'timetics_settings', timetics_get_settings() );
87 $is_admin = current_user_can( 'manage_timetics' );
88 //only run for non user capabilities
89 if ( ! $is_admin ) {
90 $exclude_settings = $this->exclude_settings_for_customer();
91 foreach($settings as $key => $setting){
92 if( in_array( $key, $exclude_settings )){
93 unset( $settings[$key] );
94 }
95 }
96 }
97
98 $data = [
99 'status_code' => 200,
100 'success' => 1,
101 'message' => esc_html__( 'Get all settings', 'timetics' ),
102 'data' => $settings,
103 ];
104
105 return rest_ensure_response( $settings );
106 }
107
108 /**
109 * Update settings
110 *
111 * @param WP_Rest_Request $request
112 *
113 * @return JSON
114 */
115 public function update_settings( $request ) {
116 $options = json_decode( $request->get_body(), true );
117
118 /**
119 * Added temporary for leagacy sass. It will remove in future.
120 */
121 $data = [
122 'status_code' => 200,
123 'success' => 1,
124 'message' => esc_html__( 'Settings successfully updated', 'timetics' ),
125 'data' => timetics_get_settings(),
126 ];
127
128 // custom domain
129 if (!empty($options['custom_domain_url']) && isset($options['custom_domain_url'])) {
130 $custom_domain_data = [
131 'custom_domain_url' => $options['custom_domain_url'],
132 'network_slug' => $options['network_slug'],
133 ];
134 do_action('timetics_custom_domain_data', $custom_domain_data);
135 }
136
137
138 if ( !empty($options['schedule']) && $options['schedule'] && apply_filters('timetics/staff/member/availability', false)) {
139 return rest_ensure_response( apply_filters( 'timetics/admin/staff/error_data', $data, 'availability_update' ) );
140 }
141
142 if ( !empty($options['availability']) && $options['availability'] && apply_filters('timetics/staff/meeting/availability', false)) {
143 return rest_ensure_response( apply_filters( 'timetics/admin/appointment/error_data', $data, 'availability_update' ) );
144 }
145
146 if ( ! empty( $options['custom_fields'] ) && apply_filters( 'timetics/admin/settings/custom_fields', false, $options['custom_fields'] ) ) {
147 return rest_ensure_response( apply_filters( 'timetics/admin/settings/error_data', $data, 'custom_fields', timetics_get_settings() ) );
148 }
149
150 if ( ! empty( $options['paypal_status'] ) && $options['paypal_status'] && apply_filters( 'timetics/admin/settings/paypal', false ) ) {
151 return rest_ensure_response( apply_filters( 'timetics/admin/settings/error_data', $data, 'paypal', timetics_get_settings() ) );
152 }
153
154 if ( ! empty( $options['zoom_client_secret'] ) && $options['zoom_client_secret'] && apply_filters( 'timetics/admin/settings/zoom', false ) ) {
155 return rest_ensure_response( apply_filters( 'timetics/admin/settings/error_data', $data, 'zoom', timetics_get_settings() ) );
156 }
157
158 if ( ! empty( $options['fluentcrm_webhook'] ) && $options['fluentcrm_webhook'] && apply_filters( 'timetics/admin/settings/fluentcrm_webhook', false ) ) {
159 return rest_ensure_response( apply_filters( 'timetics/admin/settings/error_data', $data, 'fluent_crm', timetics_get_settings() ) );
160 }
161
162 if ( ! empty( $options['pabbly_webhook'] ) && $options['pabbly_webhook'] && apply_filters( 'timetics/admin/settings/pabbly_webhook', false ) ) {
163 return rest_ensure_response( apply_filters( 'timetics/admin/settings/error_data', $data, 'pablly', timetics_get_settings() ) );
164 }
165
166 if ( ! empty( $options['zapier_webhook'] ) && $options['zapier_webhook'] && apply_filters( 'timetics/admin/settings/zapier_webhook', false ) ) {
167 return rest_ensure_response( apply_filters( 'timetics/admin/settings/error_data', $data, 'zapier', timetics_get_settings() ) );
168 }
169
170 if (!empty($options['google_app_client_id']) && $options['google_app_client_id'] && apply_filters('timetics/admin/settings/google_calendar', false)) {
171 return rest_ensure_response(apply_filters('timetics/admin/settings/error_data', $data, 'google-calendar', timetics_get_settings()));
172 }
173
174 if ( ! empty( $options['google_app_client_secret'] ) && $options['google_app_client_secret'] && apply_filters( 'timetics/admin/settings/google-calendar', false ) ) {
175 return rest_ensure_response( apply_filters( 'timetics/admin/settings/error_data', $data, 'google-calendar', timetics_get_settings() ) );
176 }
177
178 if ( ! empty( $options['outlook_calendar'] ) && $options['outlook_calendar'] && apply_filters( 'timetics/admin/settings/outlook_calendar', false ) ) {
179 return rest_ensure_response( apply_filters( 'timetics/admin/settings/error_data', $data, 'outlook', timetics_get_settings() ) );
180 }
181
182 if ( ! empty( $options['apple_calendar'] ) && $options['apple_calendar'] && apply_filters( 'timetics/admin/settings/apple_calendar', false ) ) {
183 return rest_ensure_response( apply_filters( 'timetics/admin/settings/error_data', $data, 'paypal', timetics_get_settings() ) );
184 }
185
186 if (!empty($options['twillo_message']) && $options['twillo_message'] && apply_filters('timetics/admin/settings/twillo_messaging', false)) {
187 return rest_ensure_response(apply_filters('timetics/admin/settings/error_data', $data, 'twillo_messaging', timetics_get_settings()));
188 }
189
190 if ( $options ) {
191 foreach ( $options as $key => $value ) {
192 timetics_update_option( $key, $value );
193 }
194 }
195
196 $data['data'] = timetics_get_settings();
197
198 return rest_ensure_response( $data );
199 }
200
201 /**
202 * Business setup
203 *
204 * @param WP_Rest_Request $request
205 *
206 * @return void
207 */
208 public function setup_business( $request ) {
209 $data = json_decode( $request->get_body(), true );
210
211 $email = ! empty( $data['email'] ) ? $data['email'] : '';
212
213 $body = array(
214 'email' => $email,
215 );
216
217 $response_user = wp_remote_post( 'https://arraytics.com/?fluentcrm=1&route=contact&hash=0d9cd3d1-514d-4e1a-9147-09dfd5f9e997', ['body' => $body] );
218
219 $response = [
220 'status' => 200,
221 'success' => 1,
222 'message' => __( 'Successfully updated business', 'timetics' ),
223 ];
224
225 return rest_ensure_response( $response );
226 }
227
228 /**
229 * Get busyness categories
230 *
231 * @param WP_Rest_Request $request
232 *
233 * @return JSON
234 */
235 public function get_busyness_categories( $request ) {
236 $busyness_categories = timetics_get_busyness_categories();
237
238 $response = [
239 'success' => 1,
240 'status_code' => 200,
241 'data' => $busyness_categories,
242 ];
243
244 return rest_ensure_response( $response );
245 }
246
247 public function exclude_settings_for_customer() {
248 $allowed_keys = [
249 "booking_created_customer_email_from",
250 "booking_created_customer_email_title",
251 "booking_created_customer_email_body",
252 "booking_created_host_email_from",
253 "booking_created_host_email_title",
254 "booking_created_host_email_body",
255 "booking_canceled_customer_email_from",
256 "booking_canceled_customer_email_title",
257 "booking_canceled_customer_email_body",
258 "booking_canceled_host_email_from",
259 "booking_canceled_host_email_title",
260 "booking_canceled_host_email_body",
261 "booking_rescheduled_customer_email_from",
262 "booking_rescheduled_customer_email_title",
263 "booking_rescheduled_customer_email_body",
264 "booking_rescheduled_host_email_from",
265 "booking_rescheduled_host_email_title",
266 "booking_rescheduled_host_email_body",
267 "booking_reminder_customer_email_from",
268 "booking_reminder_customer_email_title",
269 "booking_reminder_customer_email_body",
270 "booking_reminder_host_email_from",
271 "booking_reminder_host_email_title",
272 "booking_reminder_host_email_body",
273 "google_auth_redirect_uri",
274 "google_app_client_id",
275 "google_app_client_secret",
276 "zoom_client_id",
277 "zoom_client_secret",
278 "zoom_auth_redirect_uri",
279 "fluentcrm_webhook",
280 "zapier_webhook",
281 "pabbly_webhook",
282 "twillo_account_id",
283 "twillo_token",
284 "twillo_phone_number",
285 "booking_created_customer",
286 "booking_created_host",
287 "booking_canceled_customer",
288 "booking_canceled_host",
289 "booking_rescheduled_customer",
290 "booking_rescheduled_host",
291 "booking_reminder_customer",
292 "booking_reminder_host",
293 "stripe_pub_key",
294 "stripe_secret_key",
295 "paypal_client_id",
296 "paypal_client_secret",
297 "outlook_app_client_id",
298 "outlook_app_client_secret",
299 "outlook_auth_redirect_uri",
300 ];
301
302
303 return $allowed_keys;
304 }
305 }
306