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

236 lines 8.8 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 // custom domain
118 if (!empty($options['custom_domain_url']) && isset($options['custom_domain_url'])) {
119 $custom_domain_data = [
120 'custom_domain_url' => $options['custom_domain_url'],
121 'network_slug' => $options['network_slug'],
122 ];
123 do_action('custom_domain_data', $custom_domain_data);
124 }
125
126
127 if ( !empty($options['schedule']) && $options['schedule'] && apply_filters('timetics/staff/member/availability', false)) {
128 return rest_ensure_response( apply_filters( 'timetics/admin/staff/error_data', $data, 'availability_update' ) );
129 }
130
131 if ( !empty($options['availability']) && $options['availability'] && apply_filters('timetics/staff/meeting/availability', false)) {
132 return rest_ensure_response( apply_filters( 'timetics/admin/appointment/error_data', $data, 'availability_update' ) );
133 }
134
135 if ( ! empty( $options['custom_fields'] ) && apply_filters( 'timetics/admin/settings/custom_fields', false, $options['custom_fields'] ) ) {
136 return rest_ensure_response( apply_filters( 'timetics/admin/settings/error_data', $data, 'custom_fields', timetics_get_settings() ) );
137 }
138
139 if ( ! empty( $options['paypal_status'] ) && $options['paypal_status'] && apply_filters( 'timetics/admin/settings/paypal', false ) ) {
140 return rest_ensure_response( apply_filters( 'timetics/admin/settings/error_data', $data, 'paypal', timetics_get_settings() ) );
141 }
142
143 if ( ! empty( $options['zoom_client_secret'] ) && $options['zoom_client_secret'] && apply_filters( 'timetics/admin/settings/zoom', false ) ) {
144 return rest_ensure_response( apply_filters( 'timetics/admin/settings/error_data', $data, 'zoom', timetics_get_settings() ) );
145 }
146
147 if ( ! empty( $options['fluentcrm_webhook'] ) && $options['fluentcrm_webhook'] && apply_filters( 'timetics/admin/settings/fluentcrm_webhook', false ) ) {
148 return rest_ensure_response( apply_filters( 'timetics/admin/settings/error_data', $data, 'fluent_crm', timetics_get_settings() ) );
149 }
150
151 if ( ! empty( $options['pabbly_webhook'] ) && $options['pabbly_webhook'] && apply_filters( 'timetics/admin/settings/pabbly_webhook', false ) ) {
152 return rest_ensure_response( apply_filters( 'timetics/admin/settings/error_data', $data, 'pablly', timetics_get_settings() ) );
153 }
154
155 if ( ! empty( $options['zapier_webhook'] ) && $options['zapier_webhook'] && apply_filters( 'timetics/admin/settings/zapier_webhook', false ) ) {
156 return rest_ensure_response( apply_filters( 'timetics/admin/settings/error_data', $data, 'zapier', timetics_get_settings() ) );
157 }
158
159 if (!empty($options['google_app_client_id']) && $options['google_app_client_id'] && apply_filters('timetics/admin/settings/google_calendar', false)) {
160 return rest_ensure_response(apply_filters('timetics/admin/settings/error_data', $data, 'google-calendar', timetics_get_settings()));
161 }
162
163 if ( ! empty( $options['google_app_client_secret'] ) && $options['google_app_client_secret'] && apply_filters( 'timetics/admin/settings/google-calendar', false ) ) {
164 return rest_ensure_response( apply_filters( 'timetics/admin/settings/error_data', $data, 'google-calendar', timetics_get_settings() ) );
165 }
166
167 if ( ! empty( $options['outlook_calendar'] ) && $options['outlook_calendar'] && apply_filters( 'timetics/admin/settings/outlook_calendar', false ) ) {
168 return rest_ensure_response( apply_filters( 'timetics/admin/settings/error_data', $data, 'outlook', timetics_get_settings() ) );
169 }
170
171 if ( ! empty( $options['apple_calendar'] ) && $options['apple_calendar'] && apply_filters( 'timetics/admin/settings/apple_calendar', false ) ) {
172 return rest_ensure_response( apply_filters( 'timetics/admin/settings/error_data', $data, 'paypal', timetics_get_settings() ) );
173 }
174
175 if (!empty($options['twillo_message']) && $options['twillo_message'] && apply_filters('timetics/admin/settings/twillo_messaging', false)) {
176 return rest_ensure_response(apply_filters('timetics/admin/settings/error_data', $data, 'twillo_messaging', timetics_get_settings()));
177 }
178
179 if ( $options ) {
180 foreach ( $options as $key => $value ) {
181 timetics_update_option( $key, $value );
182 }
183 }
184
185 $data['data'] = timetics_get_settings();
186
187 return rest_ensure_response( $data );
188 }
189
190 /**
191 * Business setup
192 *
193 * @param WP_Rest_Request $request
194 *
195 * @return void
196 */
197 public function setup_business( $request ) {
198 $data = json_decode( $request->get_body(), true );
199
200 $email = ! empty( $data['email'] ) ? $data['email'] : '';
201
202 $body = array(
203 'email' => $email,
204 );
205
206 $response_user = wp_remote_post( 'https://arraytics.com/?fluentcrm=1&route=contact&hash=0d9cd3d1-514d-4e1a-9147-09dfd5f9e997', ['body' => $body] );
207
208 $response = [
209 'status' => 200,
210 'success' => 1,
211 'message' => __( 'Successfully updated business', 'timetics' ),
212 ];
213
214 return rest_ensure_response( $response );
215 }
216
217 /**
218 * Get busyness categories
219 *
220 * @param WP_Rest_Request $request
221 *
222 * @return JSON
223 */
224 public function get_busyness_categories( $request ) {
225 $busyness_categories = timetics_get_busyness_categories();
226
227 $response = [
228 'success' => 1,
229 'status_code' => 200,
230 'data' => $busyness_categories,
231 ];
232
233 return rest_ensure_response( $response );
234 }
235 }
236