PluginProbe
Extendify / 3.2.2
Extendify v3.2.2
3.2.2 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 All 128 releases
← All changes | app/Shared/Services/PluginsActivation/SimplyBook.php +30 -4 3.1.4 → 3.2.2 View file →
@@ -5,8 +5,12 @@
5 5 defined('ABSPATH') || die('No direct access.');
6 6
7 7 class SimplyBook extends PluginActivation
8 8 {
9 + // Plugin requires PHP 7.0; constant visibility modifiers are PHP 7.1+.
10 + // phpcs:ignore PSR12.Properties.ConstantVisibility.NotFound
11 + const AWAITING_CALLBACK = 'extendify_simplybook_awaiting_callback';
12 +
9 13 public static function slug(): string
10 14 {
11 15 return 'simplybook';
12 16 }
@@ -24,8 +28,14 @@
24 28 'recaptchaAction' => 'create_company',
25 29 ];
26 30 }
27 31
32 + public static function isEligible(): bool
33 + {
34 + // simplybook_onboarding_completed is set before the account exists, so it would hide eligible sites.
35 + return empty(\get_option('simplybook_token_admin'));
36 + }
37 +
28 38 // SimplyBook assesses the captcha itself, so a token minted with any other site key fails.
29 39 protected static function recaptchaSiteKey(): string
30 40 {
31 41 $config = WP_PLUGIN_DIR . '/' . static::slug() . '/config/env.php';
@@ -44,8 +54,11 @@
44 54 // Reset onboarding data to have a fresh start
45 55 delete_option('simplybook_onboarding_completed');
46 56 static::dispatchOnboarding('retry_onboarding');
47 57
58 + // Matches the callback URL lifetime they mint; nothing arrives later.
59 + \set_transient(self::AWAITING_CALLBACK, true, 10 * MINUTE_IN_SECONDS);
60 +
48 61 $create = static::dispatchOnboarding('create_account', [
49 62 'email' => \sanitize_email($request->get_param('email')),
50 63 'terms-and-conditions' => (bool) $request->get_param('termsAgreed'),
51 64 'marketing-consent' => (bool) $request->get_param('marketingConsent'),
@@ -51,17 +64,30 @@
51 64 'marketing-consent' => (bool) $request->get_param('marketingConsent'),
52 65 'captcha_token' => \sanitize_text_field($request->get_param('captcha_token')),
53 66 ]);
54 67 if ($create->is_error()) {
68 + \delete_transient(self::AWAITING_CALLBACK);
55 69 return $create;
56 70 }
57 71
58 - $finish = static::dispatchOnboarding('finish_onboarding');
59 - if ($finish->is_error()) {
60 - return $finish;
72 + return new \WP_REST_Response(['success' => true], 200);
73 + }
74 +
75 + // Marking onboarding complete unregisters the route their token-saving callback arrives on.
76 + public static function register()
77 + {
78 + \add_action('simplybook_after_company_registered', [self::class, 'finishOnboarding'], 10, 0);
79 + }
80 +
81 + public static function finishOnboarding()
82 + {
83 + // Their own wizard finishes this itself, at the end of its step 2.
84 + if (!\get_transient(self::AWAITING_CALLBACK)) {
85 + return;
61 86 }
62 87
63 - return new \WP_REST_Response(['success' => true], 200);
88 + \delete_transient(self::AWAITING_CALLBACK);
89 + static::dispatchOnboarding('finish_onboarding');
64 90 }
65 91
66 92 protected static function dispatchOnboarding(string $action, array $body = []): \WP_REST_Response
67 93 {