← All changes
|
app/Shared/Services/PluginsActivation/PluginActivation.php
+19
-2
3.1.5
→
trunk
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 | } |
| @@ -27,8 +32,17 @@ | ||
| 27 | 32 | { |
| 28 | 33 | return true; |
| 29 | 34 | } |
| 30 | 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 | + | |
| 31 | 45 | protected static function pluginNotActiveResponse(): \WP_REST_Response |
| 32 | 46 | { |
| 33 | 47 | return new \WP_REST_Response( |
| 34 | 48 | [ |
| @@ -54,15 +68,18 @@ | ||
| 54 | 68 | $body = (array) ($request->get_param('body') ?? []); |
| 55 | 69 | |
| 56 | 70 | $response = \wp_safe_remote_post(static::API_URL, [ |
| 57 | 71 | // http_request_args only lifts Extendify hosts, and it overrides this value if it ever matches. |
| 58 | - 'timeout' => 15, | |
| 72 | + 'timeout' => 45, | |
| 59 | 73 | 'headers' => array_merge(['Content-Type' => 'application/json'], $headers), |
| 60 | 74 | 'body' => \wp_json_encode(array_merge(['email' => $email], $body)), |
| 61 | 75 | ]); |
| 62 | 76 | |
| 63 | 77 | if (\is_wp_error($response)) { |
| 64 | - 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); | |
| 65 | 82 | } |
| 66 | 83 | |
| 67 | 84 | $code = \wp_remote_retrieve_response_code($response); |
| 68 | 85 | $data = json_decode(\wp_remote_retrieve_body($response), true) ?? []; |