PluginProbe
Extendify / 0.10.2
Extendify v0.10.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 0.6.0 All 127 releases
extendify / app / Config.php

Config.php in Extendify 0.10.2, at app/Config.php

175 lines 4.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The App details file
4 */
5
6 namespace Extendify;
7
8 /**
9 * Controller for handling various app data
10 */
11 class Config
12 {
13
14 /**
15 * Plugin name
16 *
17 * @var string
18 */
19 public static $name = '';
20
21 /**
22 * Plugin slug
23 *
24 * @var string
25 */
26 public static $slug = '';
27
28 /**
29 * Plugin version
30 *
31 * @var string
32 */
33 public static $version = '';
34
35 /**
36 * Plugin API REST version
37 *
38 * @var string
39 */
40 public static $apiVersion = 'v1';
41
42 /**
43 * Whether this is the standalone plugin
44 *
45 * @var boolean
46 */
47 public static $standalone;
48
49 /**
50 * Whether to load Launch
51 *
52 * @var boolean
53 */
54 public static $showOnboarding = false;
55
56 /**
57 * Whether to load Assist
58 *
59 * @var boolean
60 */
61 public static $showAssist = false;
62
63 /**
64 * Plugin environment
65 *
66 * @var string
67 */
68 public static $environment = '';
69
70 /**
71 * The partner plugin/theme
72 *
73 * @var string
74 */
75 public static $sdkPartner = 'standalone';
76
77 /**
78 * Host plugin
79 *
80 * @var string
81 */
82 public static $requiredCapability = 'manage_options';
83
84 /**
85 * Plugin config
86 *
87 * @var array
88 */
89 public static $config = [];
90
91 /**
92 * Whether Launch was finished
93 *
94 * @var mixed
95 */
96 public static $launchCompleted = 0;
97
98 /**
99 * Process the readme file to get version and name
100 *
101 * @return void
102 */
103 public function __construct()
104 {
105 self::$launchCompleted = get_option('extendify_onboarding_completed', 0);
106
107 if (isset($GLOBALS['extendify_sdk_partner']) && $GLOBALS['extendify_sdk_partner']) {
108 self::$sdkPartner = $GLOBALS['extendify_sdk_partner'];
109 }
110
111 // Set up whether this is the standalone plugin instead of integrated.
112 self::$standalone = self::$sdkPartner === 'standalone';
113
114 // TODO: Previous way to set the partner name - can remove in future.
115 if (defined('EXTENDIFY_PARTNER_NAME')) {
116 self::$sdkPartner = constant('EXTENDIFY_PARTNER_NAME');
117 }
118
119 // Always use the partner ID if set as a constant.
120 if (defined('EXTENDIFY_PARTNER_ID')) {
121 self::$sdkPartner = constant('EXTENDIFY_PARTNER_ID');
122 }
123
124 // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
125 $readme = file_get_contents(EXTENDIFY_PATH . 'readme.txt');
126
127 preg_match('/=== (.+) ===/', $readme, $matches);
128 self::$name = $matches[1];
129 self::$slug = strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', self::$name), '-'));
130
131 preg_match('/Stable tag: ([0-9.:]+)/', $readme, $matches);
132 self::$version = $matches[1];
133
134 // An easy way to check if we are in dev mode is to look for a dev specific file.
135 $isDev = is_readable(EXTENDIFY_PATH . 'public/build/.devbuild');
136
137 self::$environment = $isDev ? 'DEVELOPMENT' : 'PRODUCTION';
138 self::$showOnboarding = $this->showOnboarding();
139
140 // If they can see onboarding, or they've completed it, they can see assist.
141 self::$showAssist = self::$launchCompleted || self::$showOnboarding;
142
143 // Add the config.
144 // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
145 $config = file_get_contents(EXTENDIFY_PATH . 'config.json');
146 self::$config = json_decode($config, true);
147 }
148
149 /**
150 * Conditionally load Extendify Launch.
151 *
152 * @return boolean
153 */
154 private function showOnboarding()
155 {
156 // Always show it for dev mode.
157 if (self::$environment === 'DEVELOPMENT') {
158 return true;
159 }
160
161 // Currently we require a flag to be set.
162 if (!defined('EXTENDIFY_SHOW_ONBOARDING')) {
163 return false;
164 }
165
166 // Check if they disabled it and respect that.
167 if (constant('EXTENDIFY_SHOW_ONBOARDING') === false) {
168 return false;
169 }
170
171 // time() will be truthy and 0 falsy, so we reverse it.
172 return !self::$launchCompleted;
173 }
174 }
175