PluginProbe
Extendify / 2.1.0
Extendify v2.1.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 0.8.0 All 125 releases
extendify / bootstrap.php

bootstrap.php in Extendify 2.1.0, at bootstrap.php

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