PluginProbe
Extendify / 3.0.0
Extendify v3.0.0
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 / bootstrap.php

bootstrap.php in Extendify 3.0.0, at bootstrap.php

216 lines 6.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Bootstrap the application
5 */
6
7 defined('ABSPATH') || die('No direct access.');
8
9 use Extendify\AdminPageRouter;
10 use Extendify\Assist\Admin as AssistAdmin;
11 use Extendify\Agent\Admin as AgentAdmin;
12 use Extendify\Config;
13 use Extendify\Draft\Admin as DraftAdmin;
14 use Extendify\HelpCenter\Admin as HelpCenterAdmin;
15 use Extendify\Insights;
16 use Extendify\Launch\Admin as LaunchAdmin;
17 use Extendify\AutoLaunch\Admin as AutoLaunchAdmin;
18 use Extendify\Library\Admin as LibraryAdmin;
19 use Extendify\Library\Frontend as LibraryFrontend;
20 use Extendify\Agent\Frontend as AgentFrontend;
21 use Extendify\PageCreator\Admin as PageCreatorAdmin;
22 use Extendify\PartnerData;
23 use Extendify\Recommendations\Admin as RecommendationsAdmin;
24 use Extendify\PluginNotifications\Admin as PluginNotificationsAdmin;
25 use Extendify\Shared\Admin as SharedAdmin;
26 use Extendify\Shared\DataProvider\ResourceData;
27 use Extendify\Shared\Services\Import\ImagesImporter;
28 use Extendify\Shared\Services\PluginRedirectDisabler;
29 use Extendify\Shared\Services\VersionMigrator;
30
31 if (!defined('EXTENDIFY_REQUIRED_CAPABILITY')) {
32 define('EXTENDIFY_REQUIRED_CAPABILITY', 'manage_options');
33 }
34
35 if (!defined('EXTENDIFY_PATH')) {
36 define('EXTENDIFY_PATH', \plugin_dir_path(__FILE__));
37 }
38
39 if (!defined('EXTENDIFY_URL')) {
40 define('EXTENDIFY_URL', \plugin_dir_url(__FILE__));
41 }
42
43 if (!defined('EXTENDIFY_PLUGIN_BASENAME')) {
44 define('EXTENDIFY_PLUGIN_BASENAME', \plugin_basename(__DIR__ . '/extendify.php'));
45 }
46
47 if (is_readable(EXTENDIFY_PATH . 'vendor/autoload.php')) {
48 require EXTENDIFY_PATH . 'vendor/autoload.php';
49 }
50
51 if (!defined('EXTENDIFY_IS_THEME_EXTENDABLE')) {
52 define('EXTENDIFY_IS_THEME_EXTENDABLE', get_option('stylesheet') === 'extendable');
53 }
54
55 (static function () {
56 // This file should have no dependencies and always load.
57 new LibraryFrontend();
58 // This file hooks into an external task and should always load.
59 new Insights();
60 // This class set up the image import check scheduler.
61 new ImagesImporter();
62
63 // Run various database updates depending on the plugin version.
64 new VersionMigrator();
65
66 // This class will fetch and cache partner data to be used
67 // throughout every class below. If opt in.
68 new PartnerData();
69
70 // Set up scheduled cache (if opt-in and active).
71 if (!PartnerData::setting('deactivated')) {
72 ResourceData::scheduleCache();
73 }
74
75 if (!current_user_can(EXTENDIFY_REQUIRED_CAPABILITY)) {
76 return;
77 }
78
79 // The config class will collect information about the
80 // partner and plugin, so it's easier to access.
81 new Config();
82 if (!defined('EXTENDIFY_DEVMODE')) {
83 define('EXTENDIFY_DEVMODE', Config::$environment === 'DEVELOPMENT');
84 }
85
86 // This is a global "loader" class that loads in any assets that are shared everywhere.
87 new SharedAdmin();
88 // This class will handle loading library assets.
89 new LibraryAdmin();
90 if (PartnerData::setting('hidePluginNotifications')) {
91 new PluginNotificationsAdmin();
92 }
93
94 // Only load these if the partner ID is set. These are all opt-in features.
95 if (!Config::$partnerId && !constant('EXTENDIFY_DEVMODE')) {
96 return;
97 }
98
99 if (PartnerData::setting('deactivated')) {
100 return;
101 }
102
103 // This class handles the admin pages required for the plugin.
104 new AdminPageRouter();
105 new PluginRedirectDisabler();
106
107 // This class will handle loading page creator assets.
108 if (PartnerData::setting('showAIPageCreation') || constant('EXTENDIFY_DEVMODE')) {
109 new PageCreatorAdmin();
110 }
111
112 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
113 $page = sanitize_text_field(wp_unslash($_GET['page'] ?? ''));
114
115 if ($page === 'extendify-launch') {
116 new LaunchAdmin();
117 return;
118 }
119
120 if ($page === 'extendify-auto-launch') {
121 new AutoLaunchAdmin();
122 return;
123 }
124
125 // The remaining classes handle loading assets for each individual products.
126 // They are essentially asset loading classes.
127 if ($page === 'extendify-assist') {
128 new AssistAdmin();
129 }
130
131 $extendifyShowAgent = constant('EXTENDIFY_IS_THEME_EXTENDABLE')
132 && Config::$launchCompleted
133 && (PartnerData::setting('showAIAgents') || Config::preview('ai-agent'));
134
135 if (!$extendifyShowAgent) {
136 new HelpCenterAdmin();
137 }
138
139 if (PartnerData::setting('showProductRecommendations') || constant('EXTENDIFY_DEVMODE')) {
140 new RecommendationsAdmin();
141 }
142
143 if (PartnerData::setting('showDraft') || constant('EXTENDIFY_DEVMODE')) {
144 new DraftAdmin();
145 }
146
147 if ($extendifyShowAgent || constant('EXTENDIFY_DEVMODE')) {
148 new AgentAdmin();
149 new AgentFrontend();
150 }
151 })();
152
153 (static function () {
154 if (!current_user_can(EXTENDIFY_REQUIRED_CAPABILITY)) {
155 return;
156 }
157
158 // This loads in all the REST API routes used by the plugin.
159 require EXTENDIFY_PATH . 'routes/api.php';
160 })();
161
162 // This file is used to update the plugin and removed before w.org release.
163 if (is_readable(EXTENDIFY_PATH . '/updater.php')) {
164 require EXTENDIFY_PATH . 'updater.php';
165 }
166
167 add_action('init', function () {
168 load_plugin_textdomain('extendify-local', false, dirname(plugin_basename(__FILE__)) . '/languages/php');
169 });
170
171 // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter
172 add_filter('load_script_translation_file', function ($file, $handle, $domain) {
173 if ($domain !== 'extendify-local') {
174 return $file;
175 }
176
177 return extendifyResolveFallbackLocaleFile($file);
178 }, 10, 3);
179
180 add_filter('load_textdomain_mofile', function ($mofile, $domain) {
181 if ($domain !== 'extendify-local') {
182 return $mofile;
183 }
184
185 return extendifyResolveFallbackLocaleFile($mofile);
186 }, 10, 2);
187
188 /**
189 * Resolves a fallback translation file path if the requested locale is unsupported.
190 *
191 * This function checks if the current file path includes an unsupported locale
192 * and replaces it with a supported fallback (e.g. es_AR → es_ES),
193 * as long as the fallback file exists on disk.
194 *
195 * @param string $filepath The original .mo or .json translation file path.
196 * @return string The fallback file path if it exists, or the original one.
197 */
198
199 function extendifyResolveFallbackLocaleFile($filepath)
200 {
201 if (str_contains($filepath, '-es_') && !file_exists($filepath)) {
202 $fallbackFile = preg_replace('/-es_[A-Z]{2}/', '-es_ES', $filepath);
203 if ($fallbackFile && file_exists($fallbackFile)) {
204 return $fallbackFile;
205 }
206 }
207
208 return $filepath;
209 }
210
211 // To cover legacy conflicts.
212 // phpcs:ignore
213 class ExtendifySdk
214 {
215 }
216