PluginProbe
Extendify / 0.11.1
Extendify v0.11.1
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.11.1, 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 boolean
95 */
96 public static $launchCompleted = false;
97
98 /**
99 * Process the readme file to get version and name
100 *
101 * @return void
102 */
103 public function __construct()
104 {
105 if (isset($GLOBALS['extendify_sdk_partner']) && $GLOBALS['extendify_sdk_partner']) {
106 self::$sdkPartner = $GLOBALS['extendify_sdk_partner'];
107 }
108
109 // Set up whether this is the standalone plugin instead of integrated.
110 self::$standalone = self::$sdkPartner === 'standalone';
111
112 // TODO: Previous way to set the partner name - can remove in future.
113 if (defined('EXTENDIFY_PARTNER_NAME')) {
114 self::$sdkPartner = constant('EXTENDIFY_PARTNER_NAME');
115 }
116
117 // Always use the partner ID if set as a constant.
118 if (defined('EXTENDIFY_PARTNER_ID')) {
119 self::$sdkPartner = constant('EXTENDIFY_PARTNER_ID');
120 }
121
122 // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
123 $readme = file_get_contents(EXTENDIFY_PATH . 'readme.txt');
124
125 preg_match('/=== (.+) ===/', $readme, $matches);
126 self::$name = $matches[1];
127 self::$slug = strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', self::$name), '-'));
128
129 preg_match('/Stable tag: ([0-9.:]+)/', $readme, $matches);
130 self::$version = $matches[1];
131
132 if (!get_option('extendify_first_installed_version')) {
133 update_option('extendify_first_installed_version', self::$version);
134 }
135
136 // An easy way to check if we are in dev mode is to look for a dev specific file.
137 $isDev = is_readable(EXTENDIFY_PATH . 'public/build/.devbuild');
138
139 self::$environment = $isDev ? 'DEVELOPMENT' : 'PRODUCTION';
140 self::$launchCompleted = (bool) get_option('extendify_onboarding_completed') || $isDev;
141 self::$showOnboarding = $this->showOnboarding();
142 self::$showAssist = self::$launchCompleted || self::$showOnboarding;
143
144 // Add the config.
145 // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
146 $config = file_get_contents(EXTENDIFY_PATH . 'config.json');
147 self::$config = json_decode($config, true);
148 }
149
150 /**
151 * Conditionally load Extendify Launch.
152 *
153 * @return boolean
154 */
155 private function showOnboarding()
156 {
157 // Always show it for dev mode.
158 if (self::$environment === 'DEVELOPMENT') {
159 return true;
160 }
161
162 // Currently we require a flag to be set.
163 if (!defined('EXTENDIFY_SHOW_ONBOARDING')) {
164 return false;
165 }
166
167 // Check if they disabled it and respect that.
168 if (constant('EXTENDIFY_SHOW_ONBOARDING') === false) {
169 return false;
170 }
171
172 return true;
173 }
174 }
175