-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoader.php
More file actions
564 lines (528 loc) · 22.1 KB
/
Copy pathLoader.php
File metadata and controls
564 lines (528 loc) · 22.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
<?php
/**
* The main loader class for ThemeIsle SDK
*
* @package ThemeIsleSDK
* @subpackage Loader
* @copyright Copyright (c) 2017, Marius Cristea
* @license http://opensource.org/licenses/gpl-3.0.php GNU Public License
* @since 1.0.0
*/
namespace ThemeisleSDK;
use ThemeisleSDK\Common\Module_Factory;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Singleton loader for ThemeIsle SDK.
*/
final class Loader {
/**
* Singleton instance.
*
* @var Loader instance The singleton instance
*/
private static $instance;
/**
* Current loader version.
*
* @var string $version The class version.
*/
private static $version = '2.0.0';
/**
* Holds registered products.
*
* @var array<Product> The products which use the SDK.
*/
private static $products = [];
/**
* Holds available modules to load.
*
* @var array The modules which SDK will be using.
*/
private static $available_modules = [
'script_loader',
'dashboard_widget',
'rollback',
'uninstall_feedback',
'licenser',
'logger',
'translate',
'translations',
'review',
'recommendation',
'notification',
'promotions',
'welcome',
'compatibilities',
'about_us',
'announcements',
'featured_plugins',
'float_widget',
'migrator',
];
/**
* Holds the labels for the modules.
*
* @var array The labels for the modules.
*/
public static $labels = [
'announcements' => [
'notice_link_label' => 'See the deals',
'max_savings' => 'Best WordPress Black Friday deals of %s — themes, plugins, hosting. Curated by the Themeisle team.',
'black_friday' => 'Black Friday Sale',
'time_left' => '%s left',
'plugin_meta_message' => 'Black Friday Sale - 60% OFF',
],
'compatibilities' => [
'notice' => '%s requires a newer version of %s. Please %supdate%s %s %s to the latest version.',
'notice2' => '%s update requires a newer version of %s. Please %supdate%s %s %s.',
'notice_theme' => '%1$sWarning:%2$s This theme has not been tested with your current version of %1$s%3$s%2$s. Please update %3$s plugin.',
'notice_plugin' => '%1$sWarning:%2$s This plugin has not been tested with your current version of %1$s%3$s%2$s. Please update %3$s %4$s.',
'theme' => 'theme',
'plugin' => 'plugin',
],
'dashboard_widget' => [
'title' => 'WordPress Guides/Tutorials',
'popular' => 'Popular %s',
'install' => 'Install',
'powered' => 'Powered by %s',
],
'licenser' => [
'activate' => 'Activate',
'invalid_msg' => 'Invalid license.',
'error_notice' => 'ERROR: Failed to connect to the license service. Please try again later. Reason: %s',
'error_notice2' => 'ERROR: Failed to validate license. Please try again in one minute.',
'error_invalid' => 'ERROR: Invalid license provided.',
'update_license' => 'Updating this theme will lose any customizations you have made. Cancel to stop, OK to update.',
'invalid_msg' => 'Invalid license.',
'already_active' => 'License is already active.',
'notice_update' => '%1$s is available. %2$sCheck out what\'s%3$s new or %4$supdate now%3$s.',
'not_active' => 'License not active.',
'deactivate' => 'Deactivate',
'renew_cta' => 'Renew license to update',
'autoactivate_notice' => '%s has been successfully activated using %s license !',
'valid' => 'Valid',
'invalid' => 'Invalid',
'notice' => 'Enter your license from %s purchase history in order to get %s updates',
'expired' => '%s license expired',
'expired_date' => 'Expired on %s',
'expired_notice' => 'Your current setup continues working, but premium features are disabled and you\'re no longer receive updates - including critical patches - or support.',
'inactive' => 'In order to benefit from updates and support for %s, please add your license code from your %spurchase history%s and validate it %shere%s.',
'no_activations' => 'No more activations left for %s. You need to upgrade your plan in order to use %s on more websites. If you need assistance, please get in touch with %s staff.',
'renew_license' => 'Renew License',
'learn_more' => 'Learn More',
],
'promotions' => [
'recommended' => 'Recommended by %s',
'installActivate' => 'Install & Activate',
'preview' => 'Preview',
'installing' => 'Installing',
'activating' => 'Activating',
'connecting' => 'Connecting to API',
'learnmore' => 'Learn More',
'activate' => 'Activate',
'all_set' => 'Awesome! You are all set!',
'woo' => [
'title' => 'More extensions from Themeisle',
'title2' => 'Recommended extensions',
'cta_install' => 'Install',
'learn_more' => 'Learn More',
'dismiss' => 'Dismiss this suggestion',
'ppom_title' => 'Product Add-Ons',
'ppom_desc' => 'Add extra custom fields & add-ons on your product pages, like sizes, colors & more.',
'spark_title1' => 'Wishlist',
'spark_title2' => 'Multi-Announcement Bars',
'spark_title3' => 'Advanced Product Review',
'spark_desc1' => 'Loyalize your customers by allowing them to save their favorite products.',
'spark_desc2' => 'Add a top notification bar on your website to highlight the latest products, offers, or upcoming events.',
'spark_desc3' => 'Enable an advanced review section, enlarging the basic review options with lots of capabilities.',
],
'feedzy' => [
'import_desc' => 'Schedule automatic content imports from any RSS feed directly to your site. %sBuilt by %s%s',
'install_now' => 'Install Now',
'by' => 'by %s',
'editor_recommends' => '%s recommends %sFeedzy%s to display entries from any RSS feed with more advanced styling and filtering options.',
],
'optimole' => [
'installOptimole' => 'Install Optimole',
'gotodash' => 'Go to Optimole dashboard',
'dismisscta' => 'Dismiss this notice.',
'message1' => 'Increase this page speed and SEO ranking by optimizing images with Optimole.',
'message3' => 'Save your server space by storing images to Optimole and deliver them optimized from 400 locations around the globe. Unlimited images, Unlimited traffic.',
'message4' => 'This image looks to be too large and would affect your site speed, we recommend you to install Optimole to optimize your images.',
'message2' => 'Leverage Optimole\'s full integration with Elementor to automatically lazyload, resize, compress to AVIF/WebP and deliver from 400 locations around the globe!',
],
'redirectionCF7' => [
'gotodash' => 'Go to Contact Forms',
'dismisscta' => 'Dismiss this notice.',
'gst' => 'Get Started Free',
'message' => 'Add URL redirects, spam protection, execute JavaScript after submissions, and more with the Redirection for CF7 free plugin.',
],
'hyve' => [
'gotodash' => 'Go to Hyve Dashboard',
'install' => 'Install Hyve',
'dismisscta' => 'Dismiss this notice.',
'message' => 'Hyve is an AI-powered chatbot that turns your WordPress content into interactive conversations, helping you efficiently handle user inquiries.',
],
'wp_full_pay' => [
'gotodash' => 'Go to WP Full Pay Settings',
'install' => 'Install WP Full Pay',
'dismisscta' => 'Dismiss this notice.',
'message' => 'Enhance your donation page with WP Full Pay—create custom Stripe forms for one-time and recurring donations, manage transactions easily, and boost support with a seamless setup.',
],
'masteriyo' => [
'gotodash' => 'Go to Masteriyo Dashboard',
'install' => 'Install Masteriyo',
'dismisscta' => 'Dismiss this notice.',
'message' => 'Transform your site into a learning hub with Masteriyo LMS. Build engaging courses with intuitive tools, track student progress effortlessly, and grow your education business with powerful marketing features and seamless payment integration.',
],
],
'welcome' => [
'ctan' => 'No, thanks.',
'ctay' => 'Upgrade Now!',
'message' => '<p>You\'ve been using <b>{product}</b> for 7 days now and we appreciate your loyalty! We also want to make sure you\'re getting the most out of our product. That\'s why we\'re offering you a special deal - upgrade to <b>{pro_product}</b> in the next 5 days and receive a discount of <b>up to 30%</b>. <a href="{cta_link}" target="_blank">Upgrade now</a> and unlock all the amazing features of <b>{pro_product}</b>!</p>',
],
'uninstall' => [
'heading_plugin' => 'What\'s wrong?',
'heading_theme' => 'What does not work for you in {theme}?',
'submit' => 'Submit',
'cta_info' => 'What info do we collect?',
'button_submit' => 'Submit & Deactivate',
'button_cancel' => 'Skip & Deactivate',
'disclosure' => [
'title' => 'Below is a detailed view of all data that Themeisle will receive if you fill in this survey. No email address or IP addresses are transmitted after you submit the survey.',
'version' => '%s %s version %s %s %s %s',
'website' => '%sCurrent website:%s %s %s %s',
'usage' => '%sUsage time:%s %s %s%s',
'reason' => '%s Uninstall reason %s %s Selected reason from the above survey %s ',
],
'options' => [
'id3' => [
'title' => 'I found a better plugin',
'placeholder' => 'What\'s the plugin\'s name?',
],
'id4' => [
'title' => 'I could not get the plugin to work',
'placeholder' => 'What problem are you experiencing?',
],
'id5' => [
'title' => 'I no longer need the plugin',
'placeholder' => 'If you could improve one thing about our product, what would it be?',
],
'id6' => [
'title' => 'It\'s a temporary deactivation. I\'m just debugging an issue.',
'placeholder' => 'What problem are you experiencing?',
],
'id7' => [
'title' => 'I don\'t know how to make it look like demo',
],
'id8' => [
'placeholder' => 'What option is missing?',
'title' => 'It lacks options',
],
'id9' => [
'title' => 'Is not working with a plugin that I need',
'placeholder' => 'What is the name of the plugin',
],
'id10' => [
'title' => 'I want to try a new design, I don\'t like {theme} style',
],
'id999' => [
'title' => 'Other',
'placeholder' => 'What can we do better?',
],
],
],
'review' => [
'notice' => '<p>Hey, it\'s great to see you have <b>{product}</b> active for a few days now. How is everything going? If you can spare a few moments to rate it on WordPress.org it would help us a lot (and boost my motivation). Cheers! <br/> <br/>~ {developer}, developer of {product}</p>',
'ctay' => 'Ok, I will gladly help.',
'ctan' => 'No, thanks.',
],
'rollback' => [
'cta' => 'Rollback to v%s',
],
'logger' => [
'notice' => 'Help improve <b>{product}</b> by sharing anonymous usage data about your setup. No personal data collected.',
'cta_y' => 'Count me in',
'cta_n' => 'No thanks',
],
'about_us' => [
'title' => 'About Us',
'heroHeader' => 'Our Story',
'heroTextFirst' => 'Themeisle was founded in 2012 by a group of passionate developers who wanted to create beautiful and functional WordPress themes and plugins. Since then, we have grown into a team of over 20 dedicated professionals who are committed to delivering the best possible products to our customers.',
'heroTextSecond' => 'At Themeisle, we offer a wide range of WordPress themes and plugins that are designed to meet the needs of both beginners and advanced users. Our products are feature-rich, easy to use, and are designed to help you create beautiful and functional websites.',
'teamImageCaption' => 'Our team in WCEU2022 in Portugal',
'newsHeading' => 'Stay connected for news & updates!',
'emailPlaceholder' => 'Your email address',
'signMeUp' => 'Sign me up',
'services' => [
'ariaLabel' => 'Themeisle services',
'trustpilotLabel' => 'Rated excellent on Trustpilot',
'trustpilotRated' => 'Rated',
'trustpilotOn' => 'on',
'trustpilotBrand' => 'Trustpilot',
'heading' => 'Expert WordPress services from the Themeisle team',
'description' => 'Done for you by the same people who build your plugins and themes.',
'cta' => 'Explore all services',
'items' => [
'websiteDesign' => [
'title' => 'Website Design',
'subtitle' => 'Built for your business',
],
'support' => [
'title' => 'Support',
'subtitle' => 'On-demand expert help',
],
'speed' => [
'title' => 'Speed Optimization',
'subtitle' => 'Core Web Vitals boost',
],
'seo' => [
'title' => 'SEO Foundation',
'subtitle' => 'Rank & get found',
],
'maintenance' => [
'title' => 'Maintenance',
'subtitle' => 'Updates, backups, security',
],
'hackedSite' => [
'title' => 'Hacked Site Repair',
'subtitle' => 'Malware removed fast',
],
],
],
'installNow' => 'Install Now',
'activate' => 'Activate',
'learnMore' => 'Learn More',
'installed' => 'Installed',
'notInstalled' => 'Not Installed',
'active' => 'Active',
'others' => [
'optimole_desc' => 'Optimole is an image optimization service that automatically optimizes your images and serves them to your visitors via a global CDN, making your website lighter, faster and helping you reduce your bandwidth usage.',
'neve_desc' => 'A fast, lightweight, customizable WordPress theme offering responsive design, speed, and flexibility for various website types.',
'landingkit_desc' => 'Turn WordPress into a landing page powerhouse with Landing Kit, map domains to pages or any other published resource.',
'sparks_desc' => 'Extend your store functionality with 8 ultra-performant features like product comparisons, variation swatches, wishlist, and more.',
'tpc_desc' => 'Design, save, and revisit your templates anytime with your personal vault on Templates Cloud.',
],
'otter-page' => [
'heading' => 'Build innovative layouts with Otter Blocks and Gutenberg',
'text' => 'Otter is a lightweight, dynamic collection of page building blocks and templates for the WordPress block editor.',
'buttons' => [
'install_otter_free' => "Install Otter - It's free!",
'install_now' => 'Install Now',
'learn_more' => 'Learn More',
],
'features' => [
'advancedTitle' => 'Advanced Features',
'advancedDesc' => 'Add features such as Custom CSS, Animations & Visibility Conditions to all blocks.',
'fastTitle' => 'Lightweight and Fast',
'fastDesc' => 'Otter enhances WordPress site building experience without impacting site speed.',
'mobileTitle' => 'Mobile-Friendly',
'mobileDesc' => 'Each block can be tweaked to provide a consistent experience across all devices.',
],
'details' => [
's1Title' => 'A Better Page Building Experience',
's1Text' => 'Otter can be used to build everything from a personal blog to an e-commerce site without losing the personal touch. Otter’s ease of use transforms basic blocks into expressive layouts in seconds.',
's2Title' => 'A New Collection of Patterns',
's2Text' => 'A New Patterns Library, containing a range of different elements in a variety of styles to help you build great pages. All of your website’s most important areas are covered: headers, testimonials, pricing tables, sections and more.',
's3Title' => 'Advanced Blocks',
's3Text' => 'Enhance your website’s design with powerful blocks, like the Add to Cart, Business Hours, Review Comparison, and dozens of WooCommerce blocks.',
],
'testimonials' => [
'heading' => 'Trusted by more than 300K website owners',
'users' => [
'user_1' => 'Loved the collection of blocks. If you want to create nice Gutenberg Pages, this plugin will be very handy and useful.',
'user_2' => 'I am very satisfied with Otter – a fantastic collection of blocks. And the plugin is perfectly integrated with Gutenberg and complete enough for my needs.',
'user_3' => 'Otter Blocks work really well and I like the customization options. Easy to use and format to fit in with my site theme – and I’ve not encountered any compatibility or speed issues.',
],
],
],
],
'float_widget' => [
'button' => 'Toggle Help Widget for %s',
'panel' => [
'greeting' => 'Thank you for using %s',
'title' => 'How can we help you?',
'close' => 'Close Toggle Help Widget',
],
'links' => [
'documentation' => 'Documentation',
'support' => 'Get Support',
'wizard' => 'Run Setup Wizard',
'upgrade' => 'Upgrade to Pro',
'feature_request' => 'Suggest a Feature',
'rate' => 'Rate Us',
],
],
];
/**
* Initialize the sdk logic.
*/
public static function init() {
self::localize_labels();
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof Loader ) ) {
self::$instance = new Loader();
$modules = array_merge( self::$available_modules, apply_filters( 'themeisle_sdk_modules', [] ) );
foreach ( $modules as $key => $module ) {
if ( ! class_exists( 'ThemeisleSDK\\Modules\\' . ucwords( $module, '_' ) ) ) {
unset( $modules[ $key ] );
}
}
self::$available_modules = $modules;
add_action( 'themeisle_sdk_first_activation', array( __CLASS__, 'activate' ) );
}
}
/**
* Localize the labels.
*/
public static function localize_labels() {
$originals = self::$labels;
$all_translations = [];
global $wp_filter;
if ( isset( $wp_filter['themeisle_sdk_labels'] ) ) {
foreach ( $wp_filter['themeisle_sdk_labels']->callbacks as $priority => $hooks ) {
foreach ( $hooks as $hook ) {
// Each callback gets fresh originals, not previous callback's output
$result = call_user_func( $hook['function'], $originals );
$all_translations[] = $result;
}
}
// Remove the filter so it doesn't run again via apply_filters
remove_all_filters( 'themeisle_sdk_labels' );
}
// Merge all results, first real translation wins
self::$labels = self::merge_all_translations( $originals, $all_translations );
}
/**
* Merge all translations.
*
* @param array $originals The original labels.
* @param array $all_translations The all translations.
*
* @return array The merged labels.
*/
private static function merge_all_translations( $originals, $all_translations ) {
$result = $originals;
foreach ( $all_translations as $translations ) {
$result = self::merge_if_translated( $result, $translations, $originals );
}
return $result;
}
/**
* Merge if translated.
*
* @param array $current The current labels.
* @param array $new The new labels.
* @param array $originals The original labels.
* @return array The merged labels.
*/
private static function merge_if_translated( $current, $new, $originals ) {
foreach ( $new as $key => $value ) {
if ( ! isset( $originals[ $key ] ) ) {
// New key, accept it
if ( ! isset( $current[ $key ] ) ) {
$current[ $key ] = $value;
}
continue;
}
if ( is_array( $value ) && is_array( $originals[ $key ] ) ) {
$current[ $key ] = self::merge_if_translated(
$current[ $key ],
$value,
$originals[ $key ]
);
} else {
// Only accept if:
// 1. New value is actually translated (differs from original)
// 2. Current value is NOT already translated
$is_new_translated = ( $value !== $originals[ $key ] );
$is_current_untranslated = ( $current[ $key ] === $originals[ $key ] );
if ( $is_new_translated && $is_current_untranslated ) {
$current[ $key ] = $value;
}
}
}
return $current;
}
/**
* Get cache token used in API requests.
*
* @return string Cache token.
*/
public static function get_cache_token() {
$cache_token = get_transient( 'themeisle_sdk_cache_token' );
if ( false === $cache_token ) {
$cache_token = wp_generate_password( 6, false );
set_transient( $cache_token, WEEK_IN_SECONDS );
}
return $cache_token;
}
/**
* Clear cache token.
*/
public static function clear_cache_token() {
delete_transient( 'themeisle_sdk_cache_token' );
}
/**
* Register product into SDK.
*
* @param string $base_file The product base file.
*
* @return Loader The singleton object.
*/
public static function add_product( $base_file ) {
if ( ! is_file( $base_file ) ) {
return self::$instance;
}
$product = new Product( $base_file );
Module_Factory::attach( $product, self::get_modules() );
self::$products[ $product->get_slug() ] = $product;
return self::$instance;
}
/**
* Activate the product routine.
*
* @param string $file The base file of the product.
*
* @return void
*/
public static function activate( $file ) {
$dirname = trailingslashit( dirname( ( $file ) ) );
if ( ! file_exists( $dirname . '_reference.php' ) ) {
return;
}
$reference_data = require_once $dirname . '_reference.php';
if ( ! is_array( $reference_data ) ||
! isset( $reference_data['key'] ) ||
! isset( $reference_data['value'] ) ||
! preg_match( '/^[a-zA-Z0-9_]+_reference_key$/', $reference_data['key'] ) ) {
return;
}
add_option( $reference_data['key'], sanitize_key( $reference_data['value'] ) );
}
/**
* Get all registered modules by the SDK.
*
* @return array Modules available.
*/
public static function get_modules() {
return self::$available_modules;
}
/**
* Get all products using the SDK.
*
* @return array<Product> Products available.
*/
public static function get_products() {
return self::$products;
}
/**
* Get the version of the SDK.
*
* @return string The version.
*/
public static function get_version() {
return self::$version;
}
}