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

206 lines 6.9 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['custom_fields'] ) && apply_filters( 'timetics/admin/settings/custom_fields', false, $options['custom_fields'] ) ) {
118 return rest_ensure_response( apply_filters( 'timetics/admin/settings/error_data', $data, 'custom_fields', timetics_get_settings() ) );
119 }
120
121 if ( ! empty( $options['paypal_status'] ) && $options['paypal_status'] && apply_filters( 'timetics/admin/settings/paypal', false ) ) {
122 return rest_ensure_response( apply_filters( 'timetics/admin/settings/error_data', $data, 'paypal', timetics_get_settings() ) );
123 }
124
125 if ( ! empty( $options['zoom_client_secret'] ) && $options['zoom_client_secret'] && apply_filters( 'timetics/admin/settings/zoom', false ) ) {
126 return rest_ensure_response( apply_filters( 'timetics/admin/settings/error_data', $data, 'zoom', timetics_get_settings() ) );
127 }
128
129 if ( ! empty( $options['fluentcrm_webhook'] ) && $options['fluentcrm_webhook'] && apply_filters( 'timetics/admin/settings/fluentcrm_webhook', false ) ) {
130 return rest_ensure_response( apply_filters( 'timetics/admin/settings/error_data', $data, 'fluent_crm', timetics_get_settings() ) );
131 }
132
133 if ( ! empty( $options['pabbly_webhook'] ) && $options['pabbly_webhook'] && apply_filters( 'timetics/admin/settings/pabbly_webhook', false ) ) {
134 return rest_ensure_response( apply_filters( 'timetics/admin/settings/error_data', $data, 'pablly', timetics_get_settings() ) );
135 }
136
137 if ( ! empty( $options['zapier_webhook'] ) && $options['zapier_webhook'] && apply_filters( 'timetics/admin/settings/zapier_webhook', false ) ) {
138 return rest_ensure_response( apply_filters( 'timetics/admin/settings/error_data', $data, 'zapier', timetics_get_settings() ) );
139 }
140
141 if ( ! empty( $options['outlook_calendar'] ) && $options['outlook_calendar'] && apply_filters( 'timetics/admin/settings/outlook_calendar', false ) ) {
142 return rest_ensure_response( apply_filters( 'timetics/admin/settings/error_data', $data, 'outlook', timetics_get_settings() ) );
143 }
144
145 if ( ! empty( $options['apple_calendar'] ) && $options['apple_calendar'] && apply_filters( 'timetics/admin/settings/apple_calendar', false ) ) {
146 return rest_ensure_response( apply_filters( 'timetics/admin/settings/error_data', $data, 'paypal', timetics_get_settings() ) );
147 } // End.
148
149 if ( $options ) {
150 foreach ( $options as $key => $value ) {
151 timetics_update_option( $key, $value );
152 }
153 }
154
155 $data['data'] = timetics_get_settings();
156
157 return rest_ensure_response( $data );
158 }
159
160 /**
161 * Business setup
162 *
163 * @param WP_Rest_Request $request
164 *
165 * @return void
166 */
167 public function setup_business( $request ) {
168 $data = json_decode( $request->get_body(), true );
169
170 $email = ! empty( $data['email'] ) ? $data['email'] : '';
171
172 $body = array(
173 'email' => $email,
174 );
175
176 $response_user = wp_remote_post( 'https://arraytics.com/?fluentcrm=1&route=contact&hash=0d9cd3d1-514d-4e1a-9147-09dfd5f9e997', ['body' => $body] );
177
178 $response = [
179 'status' => 200,
180 'success' => 1,
181 'message' => __( 'Successfully updated business', 'timetics' ),
182 ];
183
184 return rest_ensure_response( $response );
185 }
186
187 /**
188 * Get busyness categories
189 *
190 * @param WP_Rest_Request $request
191 *
192 * @return JSON
193 */
194 public function get_busyness_categories( $request ) {
195 $busyness_categories = timetics_get_busyness_categories();
196
197 $response = [
198 'success' => 1,
199 'status_code' => 200,
200 'data' => $busyness_categories,
201 ];
202
203 return rest_ensure_response( $response );
204 }
205 }
206