PluginProbe
Extendify / 2.2.2
Extendify v2.2.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 / bootstrap.php

bootstrap.php in Extendify 2.2.2, at bootstrap.php

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