PluginProbe
Extendify / 0.9.2
Extendify v0.9.2
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 0.7.0 All 126 releases
extendify / app / Config.php

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

156 lines 3.6 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 show load onboarding
51 *
52 * @var boolean
53 */
54 public static $showOnboarding = false;
55
56 /**
57 * Plugin environment
58 *
59 * @var string
60 */
61 public static $environment = '';
62
63 /**
64 * The partner plugin/theme
65 *
66 * @var string
67 */
68 public static $sdkPartner = 'standalone';
69
70 /**
71 * Host plugin
72 *
73 * @var string
74 */
75 public static $requiredCapability = 'manage_options';
76
77 /**
78 * Plugin config
79 *
80 * @var array
81 */
82 public static $config = [];
83
84 /**
85 * Process the readme file to get version and name
86 *
87 * @return void
88 */
89 public function __construct()
90 {
91 if (isset($GLOBALS['extendify_sdk_partner']) && $GLOBALS['extendify_sdk_partner']) {
92 self::$sdkPartner = $GLOBALS['extendify_sdk_partner'];
93 }
94
95 // Set up whether this is the standalone plugin instead of integrated.
96 self::$standalone = self::$sdkPartner === 'standalone';
97
98 // Always use the partner name if set as a constant.
99 if (defined('EXTENDIFY_PARTNER_NAME')) {
100 self::$sdkPartner = constant('EXTENDIFY_PARTNER_NAME');
101 }
102
103 // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
104 $readme = file_get_contents(EXTENDIFY_PATH . 'readme.txt');
105
106 preg_match('/=== (.+) ===/', $readme, $matches);
107 self::$name = $matches[1];
108 self::$slug = strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', self::$name), '-'));
109
110 preg_match('/Stable tag: ([0-9.:]+)/', $readme, $matches);
111 self::$version = $matches[1];
112
113 // An easy way to check if we are in dev mode is to look for a dev specific file.
114 $isDev = is_readable(EXTENDIFY_PATH . 'public/build/.devbuild');
115 self::$environment = $isDev ? 'DEVELOPMENT' : 'PRODUCTION';
116
117 self::$showOnboarding = $this->showOnboarding();
118
119 // Add the config.
120 // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
121 $config = file_get_contents(EXTENDIFY_PATH . 'config.json');
122 self::$config = json_decode($config, true);
123 }
124
125 /**
126 * Conditionally load Extendify Launch.
127 *
128 * @return boolean
129 */
130 private function showOnboarding()
131 {
132 // Always show it for dev mode.
133 if (self::$environment === 'DEVELOPMENT') {
134 return true;
135 }
136
137 // Currently we require a flag to be set.
138 if (!defined('EXTENDIFY_SHOW_ONBOARDING')) {
139 return false;
140 }
141
142 // Check if they disabled it and respect that.
143 if (constant('EXTENDIFY_SHOW_ONBOARDING') === false) {
144 return false;
145 }
146
147 // time() will be truthy and 0 falsy.
148 if (get_option('extendify_onboarding_skipped', 0)) {
149 return false;
150 }
151
152 // time() will be truthy and 0 falsy, so we reverse it.
153 return !get_option('extendify_onboarding_completed', 0);
154 }
155 }
156