← All changes
|
app/Shared/Services/PluginsActivation/PluginActivation.php
+25
-1
3.1.2
→
3.2.1
View file →
| @@ -7,8 +7,13 @@ | ||
| 7 | 7 | abstract class PluginActivation |
| 8 | 8 | { |
| 9 | 9 | abstract public static function slug(): string; |
| 10 | 10 | |
| 11 | + public static function createAccountRoute(): string | |
| 12 | + { | |
| 13 | + return '/' . static::slug() . '/create-account'; | |
| 14 | + } | |
| 15 | + | |
| 11 | 16 | public static function scriptData(): array |
| 12 | 17 | { |
| 13 | 18 | return []; |
| 14 | 19 | } |
| @@ -22,8 +27,22 @@ | ||
| 22 | 27 | } |
| 23 | 28 | return false; |
| 24 | 29 | } |
| 25 | 30 | |
| 31 | + public static function isEligible(): bool | |
| 32 | + { | |
| 33 | + return true; | |
| 34 | + } | |
| 35 | + | |
| 36 | + // rest_no_route names the failure better than the code we would mint. | |
| 37 | + protected static function withFallbackCode(\WP_REST_Response $response, string $code): \WP_REST_Response | |
| 38 | + { | |
| 39 | + return new \WP_REST_Response( | |
| 40 | + array_merge(['code' => $code], (array) $response->get_data()), | |
| 41 | + $response->get_status() | |
| 42 | + ); | |
| 43 | + } | |
| 44 | + | |
| 26 | 45 | protected static function pluginNotActiveResponse(): \WP_REST_Response |
| 27 | 46 | { |
| 28 | 47 | return new \WP_REST_Response( |
| 29 | 48 | [ |
| @@ -48,14 +67,19 @@ | ||
| 48 | 67 | $headers = (array) ($request->get_param('headers') ?? []); |
| 49 | 68 | $body = (array) ($request->get_param('body') ?? []); |
| 50 | 69 | |
| 51 | 70 | $response = \wp_safe_remote_post(static::API_URL, [ |
| 71 | + // http_request_args only lifts Extendify hosts, and it overrides this value if it ever matches. | |
| 72 | + 'timeout' => 45, | |
| 52 | 73 | 'headers' => array_merge(['Content-Type' => 'application/json'], $headers), |
| 53 | 74 | 'body' => \wp_json_encode(array_merge(['email' => $email], $body)), |
| 54 | 75 | ]); |
| 55 | 76 | |
| 56 | 77 | if (\is_wp_error($response)) { |
| 57 | - return new \WP_REST_Response(['message' => $response->get_error_message()], 500); | |
| 78 | + return new \WP_REST_Response([ | |
| 79 | + 'code' => $response->get_error_code(), | |
| 80 | + 'message' => $response->get_error_message(), | |
| 81 | + ], 500); | |
| 58 | 82 | } |
| 59 | 83 | |
| 60 | 84 | $code = \wp_remote_retrieve_response_code($response); |
| 61 | 85 | $data = json_decode(\wp_remote_retrieve_body($response), true) ?? []; |