PluginProbe
Booktics – Appointment Booking Calendar for Service Businesses / 1.0.29
Booktics – Appointment Booking Calendar for Service Businesses v1.0.29
1.0.29 1.0.28 1.0.27 1.0.26 1.0.25 1.0.24 1.0.23 1.0.22 1.0.21 1.0.20 1.0.19 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.2 1.0.3 All 31 releases
← All changes | core/extensions/controllers/module-controller.php +113 -2 1.0.17 → 1.0.29 View file →
@@ -125,8 +125,12 @@
125 125 );
126 126 }
127 127
128 128 foreach ($types[$type] as $data) {
129 + if ( isset( $data['slug'] ) && 'woocommerce' === $data['slug'] ) {
130 + $data = $this->enrich_woocommerce( $data );
131 + }
132 +
129 133 $modules_list[] = $data;
130 134 }
131 135
132 136 return $this->response($modules_list);
@@ -132,8 +136,48 @@
132 136 return $this->response($modules_list);
133 137 }
134 138
135 139 /**
140 + * Attach WooCommerce install state to the module card payload.
141 + *
142 + * The Modules screen does not load the settings REST payload, so the card
143 + * has no other way to know whether WooCommerce is installed. With this it
144 + * can offer the same Install/Activate action the settings panel does.
145 + *
146 + * @param array $data WooCommerce module row.
147 + * @return array
148 + */
149 + protected function enrich_woocommerce( array $data ): array {
150 + if ( ! function_exists( 'get_plugins' ) ) {
151 + require_once ABSPATH . 'wp-admin/includes/plugin.php';
152 + }
153 +
154 + $active = class_exists( 'WooCommerce' );
155 + $installed = $active || array_key_exists( 'woocommerce/woocommerce.php', get_plugins() );
156 +
157 + $data['woocommerce_install_status'] = $active ? 1 : 0;
158 +
159 + // Installed but switched off gets a real one-click activation; not
160 + // installed at all is sent to WordPress' own plugin install screen.
161 + // Built with add_query_arg, not wp_nonce_url: the latter esc_html's its
162 + // output (& -> &), which survives an HTML href but breaks once the
163 + // URL is carried through JSON and assigned to window.location.
164 + $data['woocommerce_activate_url'] = ( $installed && ! $active )
165 + ? add_query_arg(
166 + array(
167 + 'action' => 'activate',
168 + 'plugin' => 'woocommerce/woocommerce.php',
169 + '_wpnonce' => wp_create_nonce( 'activate-plugin_woocommerce/woocommerce.php' ),
170 + ),
171 + admin_url( 'plugins.php' )
172 + )
173 + : '';
174 + $data['woocommerce_install_url'] = admin_url( 'plugin-install.php?tab=plugin-information&plugin=woocommerce&TB_iframe=true' );
175 +
176 + return $data;
177 + }
178 +
179 + /**
136 180 * Update extension status
137 181 *
138 182 * @since 1.0.0
139 183 *
@@ -173,8 +217,41 @@
173 217 'invalid_status'
174 218 );
175 219 }
176 220
221 + // WooCommerce is a module in this list, but Install/Activate act on the
222 + // WooCommerce *plugin*, not the module toggle. Handle it up front so the
223 + // Modules card can bring WooCommerce up in place, without bouncing the
224 + // admin to wp-admin/plugins.php.
225 + if ( 'woocommerce' === $name && in_array( $status, array( 'install', 'activate' ), true ) ) {
226 + if ( 'install' === $status && ! $this->plugin_manager::is_installed( 'woocommerce' ) ) {
227 + $installed = $this->plugin_manager->install_plugin( 'woocommerce' );
228 +
229 + if ( is_wp_error( $installed ) ) {
230 + return $this->error( $installed->get_error_message(), 500, 'operation_failed' );
231 + }
232 +
233 + if ( false === $installed ) {
234 + return $this->error( __( 'Could not install WooCommerce.', 'booktics' ), 500, 'operation_failed' );
235 + }
236 + }
237 +
238 + $activated = $this->plugin_manager->activate_plugin( 'woocommerce' );
239 +
240 + if ( is_wp_error( $activated ) ) {
241 + return $this->error( $activated->get_error_message(), 500, 'operation_failed' );
242 + }
243 +
244 + if ( false === $activated ) {
245 + return $this->error( __( 'Could not activate WooCommerce.', 'booktics' ), 500, 'operation_failed' );
246 + }
247 +
248 + return $this->response(
249 + array( 'name' => $name, 'status' => 'activate' ),
250 + __( 'WooCommerce activated successfully', 'booktics' )
251 + );
252 + }
253 +
177 254 $extension = $this->extensions->find($name);
178 255
179 256 if (!$extension) {
180 257 return $this->error(
@@ -184,9 +261,9 @@
184 261 'extension_not_found'
185 262 );
186 263 }
187 264
188 - if ( 'module' == $extension['type'] ) {
265 + if ( in_array( $extension['type'], array( 'module', 'integration' ), true ) ) {
189 266 $result = $this->extensions->update($name, $status);
190 267
191 268 if (false === $result) {
192 269 return $this->error(
@@ -198,9 +275,20 @@
198 275 }
199 276
200 277 $this->update_relevant_settings($name, $status);
201 278
202 - return $this->response( [
279 + /**
280 + * Fires after a module has been turned on or off.
281 + *
282 + * Lets a module react to being enabled without polling, e.g. to
283 + * reset a throttle so its first sync runs immediately.
284 + *
285 + * @param string $name Module slug.
286 + * @param string $status New status.
287 + */
288 + do_action( 'booktics_module_status_updated', $name, $status );
289 +
290 + return $this->response( [
203 291 'name' => $name,
204 292 'status' => $status
205 293 ],
206 294 /* translators: %s: extension name */
@@ -265,8 +353,15 @@
265 353 booktics_update_option('paypal_connected', $is_enabled);
266 354 booktics_update_option('enable_paypal', $is_enabled);
267 355 break;
268 356
357 + case 'woocommerce':
358 + // The booking frontend gates the gateway on this setting, so a
359 + // module toggled from the Modules screen must flip it too;
360 + // otherwise the module boots but no customer can select it.
361 + booktics_update_option('enable_woocommerce_payment', $is_enabled);
362 + break;
363 +
269 364 case 'google-calendar':
270 365 booktics_update_option('google_redirect_url', booktics_get_auth_redirect_uri('google-auth'));
271 366 booktics_update_option('google_calendar_connected', false);
272 367 booktics_update_option('enable_google_calendar', $is_enabled);
@@ -278,8 +373,24 @@
278 373 break;
279 374
280 375 case 'fluentcrm':
281 376 booktics_update_option('enable_fluentcrm', $is_enabled);
377 + break;
378 +
379 + case 'pabbly':
380 + booktics_update_option('enable_pabbly', $is_enabled);
381 + break;
382 +
383 + case 'zapier':
384 + booktics_update_option('enable_zapier', $is_enabled);
385 + break;
386 +
387 + case 'zoho':
388 + booktics_update_option('enable_zoho', $is_enabled);
389 + break;
390 +
391 + case 'mailpoet':
392 + booktics_update_option('enable_mailpoet', $is_enabled);
282 393 break;
283 394 }
284 395 }
285 396 }