PluginProbe
Extendify / 3.1.3
Extendify v3.1.3
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
extendify / app / Shared / Services / PluginsActivation / SimplyBook.php

SimplyBook.php in Extendify 3.1.3, at app/Shared/Services/PluginsActivation/SimplyBook.php

56 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Extendify\Shared\Services\PluginsActivation;
4
5 defined('ABSPATH') || die('No direct access.');
6
7 class SimplyBook extends PluginActivation
8 {
9 public static function slug(): string
10 {
11 return 'simplybook';
12 }
13
14 protected static function simplybookNonce(): string
15 {
16 return \wp_create_nonce('simplybook_nonce');
17 }
18
19 public static function createAccount(\WP_REST_Request $request): \WP_REST_Response
20 {
21 if (!static::isActive()) {
22 return static::pluginNotActiveResponse();
23 }
24
25 // Reset onboarding data to have a fresh start
26 delete_option('simplybook_onboarding_completed');
27 static::dispatchOnboarding('retry_onboarding');
28
29 $create = static::dispatchOnboarding('create_account', [
30 'email' => \sanitize_email($request->get_param('email')),
31 'terms-and-conditions' => (bool) $request->get_param('termsAgreed'),
32 'marketing-consent' => (bool) $request->get_param('marketingConsent'),
33 'captcha_token' => \sanitize_text_field($request->get_param('captcha_token')),
34 ]);
35 if ($create->is_error()) {
36 return $create;
37 }
38
39 $finish = static::dispatchOnboarding('finish_onboarding');
40 if ($finish->is_error()) {
41 return $finish;
42 }
43
44 return new \WP_REST_Response(['success' => true], 200);
45 }
46
47 protected static function dispatchOnboarding(string $action, array $body = []): \WP_REST_Response
48 {
49 $request = new \WP_REST_Request('POST', '/simplybook/v1/onboarding/' . $action);
50 $request->set_header('Content-Type', 'application/json');
51 $request->set_body(\wp_json_encode(array_merge($body, ['nonce' => static::simplybookNonce()])));
52
53 return \rest_do_request($request);
54 }
55 }
56