PluginProbe
Extendify / 0.8.2
Extendify v0.8.2
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 0.8.0 All 125 releases
extendify / app / Config.php

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

154 lines 3.5 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 // Always use the partner name if set as a constant.
96 if (defined('EXTENDIFY_PARTNER_NAME')) {
97 self::$sdkPartner = constant('EXTENDIFY_PARTNER_NAME');
98 }
99
100 // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
101 $readme = file_get_contents(EXTENDIFY_PATH . 'readme.txt');
102
103 preg_match('/=== (.+) ===/', $readme, $matches);
104 self::$name = $matches[1];
105 self::$slug = strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', self::$name), '-'));
106
107 preg_match('/Stable tag: ([0-9.:]+)/', $readme, $matches);
108 self::$version = $matches[1];
109
110 // An easy way to check if we are in dev mode is to look for a dev specific file.
111 $isDev = is_readable(EXTENDIFY_PATH . 'public/build/.devbuild');
112 self::$environment = $isDev ? 'DEVELOPMENT' : 'PRODUCTION';
113
114 self::$standalone = self::$sdkPartner === 'standalone';
115 self::$showOnboarding = $this->showOnboarding();
116
117 // Add the config.
118 // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
119 $config = file_get_contents(EXTENDIFY_PATH . 'config.json');
120 self::$config = json_decode($config, true);
121 }
122
123 /**
124 * Whether to show onboarding
125 *
126 * @return boolean
127 */
128 private function showOnboarding()
129 {
130 // Always show it for dev mode.
131 if (self::$environment === 'DEVELOPMENT') {
132 return true;
133 }
134
135 // Currently we require a flag to be set.
136 if (!defined('EXTENDIFY_SHOW_ONBOARDING')) {
137 return false;
138 }
139
140 // Check if they disabled it and respect that.
141 if (constant('EXTENDIFY_SHOW_ONBOARDING') === false) {
142 return false;
143 }
144
145 // time() will be truthy and 0 falsy.
146 if (get_option('extendify_onboarding_skipped', 0)) {
147 return false;
148 }
149
150 // time() will be truthy and 0 falsy, so we reverse it.
151 return !get_option('extendify_onboarding_completed', 0);
152 }
153 }
154