forked from ElementorProGPL/elementor-pro-gpl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.php
550 lines (448 loc) · 14.5 KB
/
plugin.php
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
<?php
namespace ElementorPro;
use ElementorPro\Core\Admin\Admin;
use ElementorPro\Core\App\App;
use ElementorPro\Core\Connect;
use ElementorPro\Core\Compatibility\Compatibility;
use Elementor\Core\Responsive\Files\Frontend as FrontendFile;
use Elementor\Utils;
use ElementorPro\Core\Editor\Editor;
use ElementorPro\Core\Integrations\Integrations_Manager;
use ElementorPro\Core\Modules_Manager;
use ElementorPro\Core\Notifications\Notifications_Manager;
use ElementorPro\Core\Preview\Preview;
use ElementorPro\Core\Updater\Updater;
use ElementorPro\Core\Upgrade\Manager as UpgradeManager;
use ElementorPro\License\API;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* Main class plugin
*/
class Plugin {
/**
* @var Plugin
*/
private static $_instance;
/**
* @var Modules_Manager
*/
public $modules_manager;
/**
* @var UpgradeManager
*/
public $upgrade;
/**
* @var Editor
*/
public $editor;
/**
* @var Preview
*/
public $preview;
/**
* @var Admin
*/
public $admin;
/**
* @var App
*/
public $app;
/**
* @var License\Admin
*/
public $license_admin;
/**
* @var \ElementorPro\Core\Integrations\Integrations_Manager
*/
public $integrations;
/**
* @var \ElementorPro\Core\Notifications\Notifications_Manager
*/
public $notifications;
private $classes_aliases = [
'ElementorPro\Modules\PanelPostsControl\Module' => 'ElementorPro\Modules\QueryControl\Module',
'ElementorPro\Modules\PanelPostsControl\Controls\Group_Control_Posts' => 'ElementorPro\Modules\QueryControl\Controls\Group_Control_Posts',
'ElementorPro\Modules\PanelPostsControl\Controls\Query' => 'ElementorPro\Modules\QueryControl\Controls\Query',
];
/**
* Throw error on object clone
*
* The whole idea of the singleton design pattern is that there is a single
* object therefore, we don't want the object to be cloned.
*
* @since 1.0.0
* @return void
*/
public function __clone() {
_doing_it_wrong(
__FUNCTION__,
sprintf( 'Cloning instances of the singleton "%s" class is forbidden.', get_class( $this ) ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
'1.0.0'
);
}
/**
* Disable unserializing of the class
*
* @since 1.0.0
* @return void
*/
public function __wakeup() {
_doing_it_wrong(
__FUNCTION__,
sprintf( 'Unserializing instances of the singleton "%s" class is forbidden.', get_class( $this ) ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
'1.0.0'
);
}
/**
* @return \Elementor\Plugin
*/
public static function elementor() {
return \Elementor\Plugin::$instance;
}
/**
* @return Plugin
*/
public static function instance() {
if ( is_null( self::$_instance ) ) {
self::$_instance = new self();
}
return self::$_instance;
}
public function autoload( $class ) {
if ( 0 !== strpos( $class, __NAMESPACE__ ) ) {
return;
}
$has_class_alias = isset( $this->classes_aliases[ $class ] );
// Backward Compatibility: Save old class name for set an alias after the new class is loaded
if ( $has_class_alias ) {
$class_alias_name = $this->classes_aliases[ $class ];
$class_to_load = $class_alias_name;
} else {
$class_to_load = $class;
}
if ( ! class_exists( $class_to_load ) ) {
$filename = strtolower(
preg_replace(
[ '/^' . __NAMESPACE__ . '\\\/', '/([a-z])([A-Z])/', '/_/', '/\\\/' ],
[ '', '$1-$2', '-', DIRECTORY_SEPARATOR ],
$class_to_load
)
);
$filename = ELEMENTOR_PRO_PATH . $filename . '.php';
if ( is_readable( $filename ) ) {
include( $filename );
}
}
if ( $has_class_alias ) {
class_alias( $class_alias_name, $class );
}
}
public function enqueue_styles() {
$suffix = $this->get_assets_suffix();
$direction_suffix = is_rtl() ? '-rtl' : '';
$frontend_file_name_base = $this->is_optimized_css_mode() ? 'frontend-lite' : 'frontend';
$frontend_file_name = $frontend_file_name_base . $direction_suffix . $suffix . '.css';
$has_custom_file = self::elementor()->breakpoints->has_custom_breakpoints();
$frontend_file_url = $this->get_frontend_file_url( $frontend_file_name, $has_custom_file );
wp_enqueue_style(
'elementor-pro',
$frontend_file_url,
[],
$has_custom_file ? null : ELEMENTOR_PRO_VERSION
);
}
public function get_frontend_file_url( $frontend_file_name, $custom_file ) {
if ( $custom_file ) {
$frontend_file = $this->get_frontend_file( $frontend_file_name );
$frontend_file_url = $frontend_file->get_url();
} else {
$frontend_file_url = ELEMENTOR_PRO_ASSETS_URL . 'css/' . $frontend_file_name;
}
return $frontend_file_url;
}
public function get_frontend_file_path( $frontend_file_name, $custom_file ) {
if ( $custom_file ) {
$frontend_file = $this->get_frontend_file( $frontend_file_name );
$frontend_file_path = $frontend_file->get_path();
} else {
$frontend_file_path = ELEMENTOR_PRO_ASSETS_PATH . 'css/' . $frontend_file_name;
}
return $frontend_file_path;
}
public function enqueue_frontend_scripts() {
$suffix = $this->get_assets_suffix();
wp_enqueue_script(
'elementor-pro-frontend',
ELEMENTOR_PRO_URL . 'assets/js/frontend' . $suffix . '.js',
$this->get_frontend_depends(),
ELEMENTOR_PRO_VERSION,
true
);
wp_set_script_translations( 'elementor-pro-frontend', 'elementor-pro', ELEMENTOR_PRO_PATH . 'languages' );
if ( self::elementor()->experiments->is_feature_active( 'e_optimized_assets_loading' ) ) {
wp_enqueue_script( 'pro-elements-handlers' );
} else {
wp_enqueue_script( 'pro-preloaded-elements-handlers' );
}
$assets_url = ELEMENTOR_PRO_ASSETS_URL;
/**
* Elementor Pro assets URL.
*
* Filters the assets URL used by Elementor Pro.
*
* By default Elementor Pro assets URL is set by the ELEMENTOR_PRO_ASSETS_URL
* constant. This hook allows developers to change this URL.
*
* @param string $assets_url Elementor Pro assets URL.
*/
$assets_url = apply_filters( 'elementor_pro/frontend/assets_url', $assets_url );
$locale_settings = [
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'elementor-pro-frontend' ),
'urls' => [
'assets' => $assets_url,
'rest' => get_rest_url(),
],
];
/**
* Localized frontend settings.
*
* Filters the localized settings used in the frontend as JavaScript variables.
*
* By default Elementor Pro passes some frontend settings to be consumed as JavaScript
* variables. This hook allows developers to add extra settings values to be consumed
* using JavaScript in the frontend.
*
* @since 1.0.0
*
* @param array $locale_settings Localized frontend settings.
*/
$locale_settings = apply_filters( 'elementor_pro/frontend/localize_settings', $locale_settings );
Utils::print_js_config(
'elementor-pro-frontend',
'ElementorProFrontendConfig',
$locale_settings
);
if ( $this->is_assets_loader_exist() ) {
$this->register_assets();
}
}
public function register_frontend_scripts() {
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
wp_register_script(
'elementor-pro-webpack-runtime',
ELEMENTOR_PRO_URL . 'assets/js/webpack-pro.runtime' . $suffix . '.js',
[],
ELEMENTOR_PRO_VERSION,
true
);
wp_register_script(
'pro-elements-handlers',
ELEMENTOR_PRO_URL . 'assets/js/elements-handlers' . $suffix . '.js',
[
'elementor-frontend',
],
ELEMENTOR_PRO_VERSION,
true
);
wp_register_script(
'pro-preloaded-elements-handlers',
ELEMENTOR_PRO_URL . 'assets/js/preloaded-elements-handlers' . $suffix . '.js',
[
'elementor-frontend',
],
ELEMENTOR_PRO_VERSION,
true
);
wp_register_script(
'smartmenus',
ELEMENTOR_PRO_URL . 'assets/lib/smartmenus/jquery.smartmenus' . $suffix . '.js',
[
'jquery',
],
'1.0.1',
true
);
if ( ! $this->is_assets_loader_exist() ) {
wp_register_script(
'elementor-sticky',
ELEMENTOR_PRO_URL . 'assets/lib/sticky/jquery.sticky' . $suffix . '.js',
[
'jquery',
],
ELEMENTOR_PRO_VERSION,
true
);
}
}
public function register_preview_scripts() {
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
wp_enqueue_script(
'elementor-pro-preview',
ELEMENTOR_PRO_URL . 'assets/js/preview' . $suffix . '.js',
[
'wp-i18n',
'elementor-frontend',
],
ELEMENTOR_PRO_VERSION,
true
);
}
public function get_responsive_stylesheet_templates( $templates ) {
$templates_paths = glob( $this->get_responsive_templates_path() . '*.css' );
foreach ( $templates_paths as $template_path ) {
$file_name = 'custom-pro-' . basename( $template_path );
$templates[ $file_name ] = $template_path;
}
return $templates;
}
public function on_elementor_init() {
$this->modules_manager = new Modules_Manager();
/** TODO: BC for Elementor v2.4.0 */
if ( class_exists( '\Elementor\Core\Upgrade\Manager' ) ) {
$this->upgrade = UpgradeManager::instance();
}
/**
* Elementor Pro init.
*
* Fires on Elementor Pro initiation, after Elementor has finished loading
* but before any headers are sent.
*
* @since 1.0.0
*/
do_action( 'elementor_pro/init' );
}
/**
* @param \Elementor\Core\Base\Document $document
*/
public function on_document_save_version( $document ) {
$document->update_meta( '_elementor_pro_version', ELEMENTOR_PRO_VERSION );
}
private function get_frontend_depends() {
$frontend_depends = [
'elementor-pro-webpack-runtime',
'elementor-frontend-modules',
];
if ( ! $this->is_assets_loader_exist() ) {
$frontend_depends[] = 'elementor-sticky';
}
return $frontend_depends;
}
private function get_responsive_templates_path() {
return ELEMENTOR_PRO_ASSETS_PATH . 'css/templates/';
}
private function add_subscription_template_access_level_to_settings( $settings ) {
// Core >= 3.2.0
if ( isset( $settings['library_connect']['current_access_level'] ) ) {
$settings['library_connect']['current_access_level'] = API::get_library_access_level();
}
return $settings;
}
private function setup_hooks() {
add_action( 'elementor/init', [ $this, 'on_elementor_init' ] );
add_action( 'elementor/frontend/before_register_scripts', [ $this, 'register_frontend_scripts' ] );
add_action( 'elementor/preview/enqueue_scripts', [ $this, 'register_preview_scripts' ] );
add_action( 'elementor/frontend/before_enqueue_scripts', [ $this, 'enqueue_frontend_scripts' ] );
add_action( 'elementor/frontend/after_enqueue_styles', [ $this, 'enqueue_styles' ] );
add_filter( 'elementor/core/breakpoints/get_stylesheet_template', [ $this, 'get_responsive_stylesheet_templates' ] );
add_action( 'elementor/document/save_version', [ $this, 'on_document_save_version' ] );
add_filter( 'elementor/editor/localize_settings', function ( $settings ) {
return $this->add_subscription_template_access_level_to_settings( $settings );
}, 11 /** After Elementor Core (Library) */ );
}
private function is_optimized_css_mode() {
$is_optimized_css_loading = self::elementor()->experiments->is_feature_active( 'e_optimized_css_loading' );
return ! Utils::is_script_debug() && $is_optimized_css_loading && ! self::elementor()->preview->is_preview_mode();
}
private function get_assets() {
$suffix = $this->get_assets_suffix();
return [
'scripts' => [
'e-sticky' => [
'src' => ELEMENTOR_PRO_URL . 'assets/lib/sticky/jquery.sticky' . $suffix . '.js',
'version' => ELEMENTOR_PRO_VERSION,
'dependencies' => [
'jquery',
],
],
],
];
}
private function register_assets() {
$assets = $this->get_assets();
if ( $assets ) {
self::elementor()->assets_loader->add_assets( $assets );
}
}
private function is_assets_loader_exist() {
return ! ! self::elementor()->assets_loader;
}
/**
* Plugin constructor.
*/
private function __construct() {
spl_autoload_register( [ $this, 'autoload' ] );
Compatibility::register_actions();
new Connect\Manager();
$this->setup_hooks();
$this->editor = new Editor();
$this->preview = new Preview();
$this->app = new App();
$this->license_admin = new License\Admin();
if ( is_user_logged_in() ) {
$this->integrations = new Integrations_Manager(); // TODO: This one is safe to move out of the condition.
$this->notifications = new Notifications_Manager();
require_once __DIR__ . '/updater/updater.php';
$config = array(
'slug' => 'elementor-pro-gpl.php',
'plugin_basename' => ELEMENTOR_PRO_PLUGIN_BASE,
'proper_folder_name' => 'elementor-pro-gpl',
'api_url' => 'https://api.github.com/repos/elementorprogpl/elementor-pro-gpl',
'raw_url' => 'https://raw.githubusercontent.com/elementorprogpl/elementor-pro-gpl/master',
'github_url' => 'https://github.com/elementorprogpl/elementor-pro-gpl',
'zip_url' => 'https://github.com/elementorprogpl/elementor-pro-gpl/archive/v{release_version}.zip',
'sslverify' => true,
'requires' => '5.0',
'tested' => '5.4.2',
'readme' => 'README.md',
'access_token' => '',
);
if ( is_admin() ) {
$this->admin = new Admin();
$this->license_admin->register_actions();
require_once __DIR__ . '/updater/updater.php';
$config = array(
'slug' => 'elementor-pro-gpl.php',
'plugin_basename' => ELEMENTOR_PRO_PLUGIN_BASE,
'proper_folder_name' => 'elementor-pro-gpl',
'api_url' => 'https://api.github.com/repos/elementorprogpl/elementor-pro-gpl',
'raw_url' => 'https://raw.githubusercontent.com/elementorprogpl/elementor-pro-gpl/master',
'github_url' => 'https://github.com/elementorprogpl/elementor-pro-gpl',
'zip_url' => 'https://github.com/elementorprogpl/elementor-pro-gpl/archive/v{release_version}.zip',
'sslverify' => true,
'requires' => '5.0',
'tested' => '5.4.2',
'readme' => 'README.md',
'access_token' => '',
);
}
new Updater( $config );
}
}
private function get_assets_suffix() {
return defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
}
private function get_frontend_file( $frontend_file_name ) {
$template_file_path = self::get_responsive_templates_path() . $frontend_file_name;
return self::elementor()->frontend->get_frontend_file( $frontend_file_name, 'custom-pro-', $template_file_path );
}
final public static function get_title() {
return esc_html__( 'ElementorProGPL', 'elementor-pro' );
}
}
if ( ! defined( 'ELEMENTOR_PRO_TESTS' ) ) {
// In tests we run the instance manually.
Plugin::instance();
}