PluginProbe
Extendify / 3.1.6
Extendify v3.1.6
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 / PluginActivation.php

PluginActivation.php in Extendify 3.1.6, at app/Shared/Services/PluginsActivation/PluginActivation.php

84 lines 2.4 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 abstract class PluginActivation
8 {
9 abstract public static function slug(): string;
10
11 public static function scriptData(): array
12 {
13 return [];
14 }
15
16 public static function isActive(): bool
17 {
18 foreach ((array) \get_option('active_plugins', []) as $plugin) {
19 if (dirname($plugin) === static::slug()) {
20 return true;
21 }
22 }
23 return false;
24 }
25
26 public static function isEligible(): bool
27 {
28 return true;
29 }
30
31 protected static function pluginNotActiveResponse(): \WP_REST_Response
32 {
33 return new \WP_REST_Response(
34 [
35 'code' => static::slug() . '_plugin_not_active',
36 'message' => sprintf(
37 /* translators: %s: plugin slug */
38 \__('The %s plugin is not active.', 'extendify-local'),
39 static::slug()
40 ),
41 ],
42 424
43 );
44 }
45
46 public static function createAccount(\WP_REST_Request $request): \WP_REST_Response
47 {
48 if (!static::isActive()) {
49 return static::pluginNotActiveResponse();
50 }
51
52 $email = \sanitize_email($request->get_param('email'));
53 $headers = (array) ($request->get_param('headers') ?? []);
54 $body = (array) ($request->get_param('body') ?? []);
55
56 $response = \wp_safe_remote_post(static::API_URL, [
57 // http_request_args only lifts Extendify hosts, and it overrides this value if it ever matches.
58 'timeout' => 15,
59 'headers' => array_merge(['Content-Type' => 'application/json'], $headers),
60 'body' => \wp_json_encode(array_merge(['email' => $email], $body)),
61 ]);
62
63 if (\is_wp_error($response)) {
64 return new \WP_REST_Response([
65 'code' => $response->get_error_code(),
66 'message' => $response->get_error_message(),
67 ], 500);
68 }
69
70 $code = \wp_remote_retrieve_response_code($response);
71 $data = json_decode(\wp_remote_retrieve_body($response), true) ?? [];
72
73 if ($code >= 200 && $code < 300) {
74 static::saveKey($data);
75 }
76
77 return new \WP_REST_Response($data, $code);
78 }
79
80 protected static function saveKey(array $data)
81 {
82 }
83 }
84