Repository navigation
Expand file tree
/
Copy pathfrontend.php
More file actions
1601 lines (1381 loc) · 40 KB
/
Copy pathfrontend.php
File metadata and controls
1601 lines (1381 loc) · 40 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
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
namespace Elementor;
use Elementor\Core\Base\App;
use Elementor\Core\Base\Elements_Iteration_Actions\Assets;
use Elementor\Core\Files\Fonts\Google_Font;
use Elementor\Core\Frontend\Render_Mode_Manager;
use Elementor\Core\Responsive\Files\Frontend as FrontendFile;
use Elementor\Core\Files\CSS\Post as Post_CSS;
use Elementor\Core\Files\CSS\Post_Preview;
use Elementor\Core\Responsive\Responsive;
use Elementor\Core\Settings\Manager as SettingsManager;
use Elementor\Core\Breakpoints\Manager as Breakpoints_Manager;
use Elementor\Modules\FloatingButtons\Module;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
/**
* Elementor frontend.
*
* Elementor frontend handler class is responsible for initializing Elementor in
* the frontend.
*
* @since 1.0.0
*/
class Frontend extends App {
/**
* The priority of the content filter.
*/
const THE_CONTENT_FILTER_PRIORITY = 9;
/**
* The priority of the frontend enqueued styles.
*/
const ENQUEUED_STYLES_PRIORITY = 20;
/**
* Post ID.
*
* Holds the ID of the current post.
*
* @access private
*
* @var int Post ID.
*/
private $post_id;
/**
* Fonts to enqueue
*
* Holds the list of fonts that are being used in the current page.
*
* @since 1.9.4
* @access public
*
* @var array Used fonts. Default is an empty array.
*/
public $fonts_to_enqueue = [];
/**
* Holds the class that respond to manage the render mode.
*
* @var Render_Mode_Manager
*/
public $render_mode_manager;
/**
* Registered fonts.
*
* Holds the list of enqueued fonts in the current page.
*
* @since 1.0.0
* @access private
*
* @var array Registered fonts. Default is an empty array.
*/
private $registered_fonts = [];
/**
* Icon Fonts to enqueue
*
* Holds the list of Icon fonts that are being used in the current page.
*
* @since 2.4.0
* @access private
*
* @var array Used icon fonts. Default is an empty array.
*/
private $icon_fonts_to_enqueue = [];
/**
* Enqueue Icon Fonts
*
* Holds the list of Icon fonts already enqueued in the current page.
*
* @since 2.4.0
* @access private
*
* @var array enqueued icon fonts. Default is an empty array.
*/
private $enqueued_icon_fonts = [];
/**
* Whether the page is using Elementor.
*
* Used to determine whether the current page is using Elementor.
*
* @since 1.0.0
* @access private
*
* @var bool Whether Elementor is being used. Default is false.
*/
private $_has_elementor_in_page = false;
/**
* Whether the excerpt is being called.
*
* Used to determine whether the call to `the_content()` came from `get_the_excerpt()`.
*
* @since 1.0.0
* @access private
*
* @var bool Whether the excerpt is being used. Default is false.
*/
private $_is_excerpt = false;
/**
* Filters removed from the content.
*
* Hold the list of filters removed from `the_content()`. Used to hold the filters that
* conflicted with Elementor while Elementor process the content.
*
* @since 1.0.0
* @access private
*
* @var array Filters removed from the content. Default is an empty array.
*/
private $content_removed_filters = [];
/**
* @var string[]
*/
private $body_classes = [
'elementor-default',
];
/**
* Front End constructor.
*
* Initializing Elementor front end. Make sure we are not in admin, not and
* redirect from old URL structure of Elementor editor.
*
* @since 1.0.0
* @access public
*/
public function __construct() {
// We don't need this class in admin side, but in AJAX requests.
if ( is_admin() && ! wp_doing_ajax() ) {
return;
}
add_action( 'template_redirect', [ $this, 'init_render_mode' ], -1 /* Before admin bar. */ );
add_action( 'template_redirect', [ $this, 'init' ] );
add_action( 'wp_enqueue_scripts', [ $this, 'register_scripts' ], 5 );
add_action( 'wp_enqueue_scripts', [ $this, 'register_styles' ], 5 );
$this->add_content_filter();
// Hack to avoid enqueue post CSS while it's a `the_excerpt` call.
add_filter( 'get_the_excerpt', [ $this, 'start_excerpt_flag' ], 1 );
add_filter( 'get_the_excerpt', [ $this, 'end_excerpt_flag' ], 20 );
if ( version_compare( get_bloginfo( 'version' ), '6.9', '>=' ) ) {
add_filter( 'wp_should_output_buffer_template_for_enhancement', '__return_false', 1 );
}
}
/**
* Get module name.
*
* Retrieve the module name.
*
* @since 2.3.0
* @access public
*
* @return string Module name.
*/
public function get_name() {
return 'frontend';
}
/**
* Init render mode manager.
*/
public function init_render_mode() {
if ( Plugin::$instance->editor->is_edit_mode() ) {
return;
}
$this->render_mode_manager = new Render_Mode_Manager();
}
/**
* Init.
*
* Initialize Elementor front end. Hooks the needed actions to run Elementor
* in the front end, including script and style registration.
*
* Fired by `template_redirect` action.
*
* @since 1.0.0
* @access public
*/
public function init() {
if ( Plugin::$instance->editor->is_edit_mode() ) {
return;
}
add_filter( 'body_class', [ $this, 'body_class' ] );
if ( Plugin::$instance->preview->is_preview_mode() ) {
return;
}
if ( current_user_can( 'manage_options' ) ) {
Plugin::$instance->init_common();
}
$this->post_id = get_the_ID();
$document = Plugin::$instance->documents->get( $this->post_id );
if ( is_singular() && $document && $document->is_built_with_elementor() ) {
add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_styles' ], self::ENQUEUED_STYLES_PRIORITY );
}
// Priority 7 to allow google fonts in header template to load in <head> tag
add_action( 'wp_head', [ $this, 'print_fonts_links' ], 7 );
add_action( 'wp_head', [ $this, 'add_theme_color_meta_tag' ] );
add_action( 'wp_footer', [ $this, 'wp_footer' ] );
}
/**
* @since 2.0.12
* @access public
* @param string|array $class_name
*/
public function add_body_class( $class_name ) {
if ( is_array( $class_name ) ) {
$this->body_classes = array_merge( $this->body_classes, $class_name );
} else {
$this->body_classes[] = $class_name;
}
}
/**
* Add Theme Color Meta Tag
*
* @since 3.0.0
* @access public
*/
public function add_theme_color_meta_tag() {
$kit = Plugin::$instance->kits_manager->get_active_kit_for_frontend();
$mobile_theme_color = $kit->get_settings( 'mobile_browser_background' );
if ( ! empty( $mobile_theme_color ) ) {
?>
<meta name="theme-color" content="<?php echo esc_attr( $mobile_theme_color ); ?>">
<?php
}
}
/**
* Body tag classes.
*
* Add new elementor classes to the body tag.
*
* Fired by `body_class` filter.
*
* @since 1.0.0
* @access public
*
* @param array $classes Optional. One or more classes to add to the body tag class list.
* Default is an empty array.
*
* @return array Body tag classes.
*/
public function body_class( $classes = [] ) {
$classes = array_merge( $classes, $this->body_classes );
$id = get_the_ID();
$document = Plugin::$instance->documents->get( $id );
if ( is_singular() && $document && $document->is_built_with_elementor() ) {
$classes[] = 'elementor-page elementor-page-' . $id;
}
if ( Plugin::$instance->preview->is_preview_mode() ) {
$editor_preferences = SettingsManager::get_settings_managers( 'editorPreferences' );
$show_hidden_elements = $editor_preferences->get_model()->get_settings( 'show_hidden_elements' );
if ( 'yes' === $show_hidden_elements ) {
$classes[] = 'e-preview--show-hidden-elements';
}
}
return $classes;
}
/**
* Add content filter.
*
* Remove plain content and render the content generated by Elementor.
*
* @since 1.8.0
* @access public
*/
public function add_content_filter() {
add_filter( 'the_content', [ $this, 'apply_builder_in_content' ], self::THE_CONTENT_FILTER_PRIORITY );
}
/**
* Remove content filter.
*
* When the Elementor generated content rendered, we remove the filter to prevent multiple
* accuracies. This way we make sure Elementor renders the content only once.
*
* @since 1.8.0
* @access public
*/
public function remove_content_filter() {
remove_filter( 'the_content', [ $this, 'apply_builder_in_content' ], self::THE_CONTENT_FILTER_PRIORITY );
}
/**
* Registers scripts.
*
* Registers all the frontend scripts.
*
* Fired by `wp_enqueue_scripts` action.
*
* @since 1.2.1
* @access public
*/
public function register_scripts() {
/**
* Before frontend register scripts.
*
* Fires before Elementor frontend scripts are registered.
*
* @since 1.2.1
*/
do_action( 'elementor/frontend/before_register_scripts' );
wp_register_script(
'elementor-webpack-runtime',
$this->get_js_assets_url( 'webpack.runtime', 'assets/js/' ),
[],
ELEMENTOR_VERSION,
true
);
wp_register_script(
'elementor-frontend-modules',
$this->get_js_assets_url( 'frontend-modules' ),
[
'elementor-webpack-runtime',
'jquery',
],
ELEMENTOR_VERSION,
true
);
wp_register_script(
'swiper',
$this->get_js_assets_url( 'swiper', 'assets/lib/swiper/v8/' ),
[],
'8.4.5',
true
);
wp_register_script(
'flatpickr',
$this->get_js_assets_url( 'flatpickr', 'assets/lib/flatpickr/' ),
[
'jquery',
],
'4.6.13',
true
);
wp_register_script(
'imagesloaded',
$this->get_js_assets_url( 'imagesloaded', 'assets/lib/imagesloaded/' ),
[
'jquery',
],
'4.1.0',
true
);
wp_register_script(
'jquery-numerator',
$this->get_js_assets_url( 'jquery-numerator', 'assets/lib/jquery-numerator/' ),
[
'jquery',
],
'0.2.1',
true
);
wp_register_script(
'elementor-dialog',
$this->get_js_assets_url( 'dialog', 'assets/lib/dialog/' ),
[
'jquery-ui-position',
],
'4.9.4',
true
);
wp_register_script(
'elementor-gallery',
$this->get_js_assets_url( 'e-gallery', 'assets/lib/e-gallery/js/' ),
[
'jquery',
],
'1.2.0',
true
);
wp_register_script(
'share-link',
$this->get_js_assets_url( 'share-link', 'assets/lib/share-link/' ),
[
'jquery',
],
ELEMENTOR_VERSION,
true
);
wp_register_script(
'elementor-frontend',
$this->get_js_assets_url( 'frontend' ),
[
'elementor-frontend-modules',
'jquery-ui-position',
],
ELEMENTOR_VERSION,
true
);
$this->register_frontend_handlers();
/**
* After frontend register scripts.
*
* Fires after Elementor frontend scripts are registered.
*
* @since 1.2.1
*/
do_action( 'elementor/frontend/after_register_scripts' );
}
/**
* Registers styles.
*
* Registers all the frontend styles.
*
* Fired by `wp_enqueue_scripts` action.
*
* @since 1.2.0
* @access public
*/
public function register_styles() {
$min_suffix = Utils::is_script_debug() ? '' : '.min';
$direction_suffix = is_rtl() ? '-rtl' : '';
$has_custom_breakpoints = Plugin::$instance->breakpoints->has_custom_breakpoints();
/**
* Before frontend register styles.
*
* Fires before Elementor frontend styles are registered.
*
* @since 1.2.0
*/
do_action( 'elementor/frontend/before_register_styles' );
wp_register_style(
'font-awesome',
$this->get_css_assets_url( 'font-awesome', 'assets/lib/font-awesome/css/' ),
[],
'4.7.0'
);
wp_register_style(
'elementor-icons',
$this->get_css_assets_url( 'elementor-icons', 'assets/lib/eicons/css/' ),
[],
Icons_Manager::ELEMENTOR_ICONS_VERSION
);
wp_register_style(
'flatpickr',
$this->get_css_assets_url( 'flatpickr', 'assets/lib/flatpickr/' ),
[],
'4.6.13'
);
wp_register_style(
'elementor-gallery',
$this->get_css_assets_url( 'e-gallery', 'assets/lib/e-gallery/css/' ),
[],
'1.2.0'
);
wp_register_style(
'e-apple-webkit',
$this->get_frontend_file_url( 'apple-webkit.min.css', $has_custom_breakpoints, 'conditionals/' ),
[],
$has_custom_breakpoints ? null : ELEMENTOR_VERSION
);
wp_register_style(
'e-swiper',
$this->get_css_assets_url( 'e-swiper', 'assets/css/conditionals/' ),
[ 'swiper' ],
ELEMENTOR_VERSION
);
wp_register_style(
'swiper',
$this->get_css_assets_url( 'swiper', 'assets/lib/swiper/v8/css/' ),
[],
'8.4.5'
);
wp_register_style(
'elementor-wp-admin-bar',
$this->get_css_assets_url( 'admin-bar', 'assets/css/' ),
[],
ELEMENTOR_VERSION
);
wp_register_style(
'e-lightbox',
$this->get_frontend_file_url( 'lightbox.min.css', $has_custom_breakpoints, 'conditionals/' ),
[],
$has_custom_breakpoints ? null : ELEMENTOR_VERSION
);
wp_register_style(
'elementor-frontend',
$this->get_frontend_file_url( "frontend{$min_suffix}.css", $has_custom_breakpoints ),
[],
$has_custom_breakpoints ? null : ELEMENTOR_VERSION
);
$widgets_with_styles = Plugin::$instance->widgets_manager->widgets_with_styles();
foreach ( $widgets_with_styles as $widget_name ) {
wp_register_style(
"widget-{$widget_name}",
$this->get_css_assets_url( "widget-{$widget_name}", null, true, true ),
[ 'elementor-frontend' ],
ELEMENTOR_VERSION
);
}
$widgets_with_responsive_styles = Plugin::$instance->widgets_manager->widgets_with_responsive_styles();
foreach ( $widgets_with_responsive_styles as $widget_name ) {
wp_register_style(
"widget-{$widget_name}",
$this->get_frontend_file_url( "widget-{$widget_name}{$direction_suffix}.min.css", $has_custom_breakpoints ),
[ 'elementor-frontend' ],
$has_custom_breakpoints ? null : ELEMENTOR_VERSION
);
}
/**
* After frontend register styles.
*
* Fires after Elementor frontend styles are registered.
*
* @since 1.2.0
*/
do_action( 'elementor/frontend/after_register_styles' );
}
/**
* Register frontend handlers.
*
* Registers all the frontend handlers for widgets and elements.
*
* Fired by `wp_enqueue_scripts` action.
*
* @since 3.25.0
* @access public
*/
public function register_frontend_handlers() {
Plugin::$instance->widgets_manager->register_frontend_handlers();
Plugin::$instance->elements_manager->register_frontend_handlers();
}
/**
* Enqueue scripts.
*
* Enqueue all the frontend scripts.
*
* @since 1.0.0
* @access public
*/
public function enqueue_scripts() {
/**
* Before frontend enqueue scripts.
*
* Fires before Elementor frontend scripts are enqueued.
*
* @since 1.0.0
*/
do_action( 'elementor/frontend/before_enqueue_scripts' );
$this->print_config();
$this->enqueue_conditional_assets();
/**
* After frontend enqueue scripts.
*
* Fires after Elementor frontend scripts are enqueued.
*
* @since 1.0.0
*/
do_action( 'elementor/frontend/after_enqueue_scripts' );
}
/**
* Enqueue styles.
*
* Enqueue all the frontend styles.
*
* Fired by `wp_enqueue_scripts` action.
*
* @since 1.0.0
* @access public
*/
public function enqueue_styles() {
static $is_enqueue_styles_already_triggered;
if ( ! $is_enqueue_styles_already_triggered ) {
$is_enqueue_styles_already_triggered = true;
/**
* Before frontend styles enqueued.
*
* Fires before Elementor frontend styles are enqueued.
*
* @since 1.0.0
*/
do_action( 'elementor/frontend/before_enqueue_styles' );
// The e-icons are needed in preview mode for the editor icons (plus-icon for new section, folder-icon for the templates library etc.).
if ( ! Plugin::$instance->experiments->is_feature_active( 'e_font_icon_svg' ) || Plugin::$instance->preview->is_preview_mode() ) {
wp_enqueue_style( 'elementor-icons' );
}
wp_enqueue_style( 'elementor-frontend' );
if ( is_admin_bar_showing() ) {
wp_enqueue_style( 'elementor-wp-admin-bar' );
}
/**
* After frontend styles enqueued.
*
* Fires after Elementor frontend styles are enqueued.
*
* @since 1.0.0
*/
do_action( 'elementor/frontend/after_enqueue_styles' );
if ( ! Plugin::$instance->preview->is_preview_mode() ) {
$post_id = get_the_ID();
// Check $post_id for virtual pages. check is singular because the $post_id is set to the first post on archive pages.
if ( $post_id && is_singular() ) {
do_action( 'elementor/post/render', $post_id );
$this->handle_page_assets( $post_id );
$css_file = Post_CSS::create( get_the_ID() );
$css_file->enqueue();
}
} else {
$post_id = Plugin::$instance->preview->get_post_id();
if ( $post_id ) {
do_action( 'elementor/post/render', $post_id );
}
}
do_action( 'elementor/frontend/after_enqueue_post_styles' );
}
}
private function handle_page_assets( $post_id ): void {
$page_assets = get_post_meta( $post_id, Assets::ASSETS_META_KEY, true );
if ( ! empty( $page_assets ) ) {
Plugin::$instance->assets_loader->enable_assets( $page_assets );
return;
}
$document = Plugin::$instance->documents->get( $post_id );
if ( ! $document ) {
return;
}
$document->update_runtime_elements();
}
/**
* Get Frontend File URL
*
* Returns the URL for the CSS file to be loaded in the front end. If requested via the second parameter, a custom
* file is generated based on a passed template file name. Otherwise, the URL for the default CSS file is returned.
*
* @since 3.4.5
*
* @access public
*
* @param string $frontend_file_name
* @param boolean $custom_file
*
* @return string frontend file URL
*/
public function get_frontend_file_url( $frontend_file_name, $custom_file, $css_subfolder = '' ) {
if ( $custom_file ) {
$frontend_file = $this->get_frontend_file( $frontend_file_name );
$frontend_file_url = $frontend_file->get_url();
} else {
$frontend_file_url = ELEMENTOR_ASSETS_URL . 'css/' . $css_subfolder . $frontend_file_name;
}
return $frontend_file_url;
}
/**
* Get Frontend File Path
*
* Returns the path for the CSS file to be loaded in the front end. If requested via the second parameter, a custom
* file is generated based on a passed template file name. Otherwise, the path for the default CSS file is returned.
*
* @since 3.5.0
* @access public
*
* @param string $frontend_file_name
* @param boolean $custom_file
*
* @return string frontend file path
*/
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_ASSETS_PATH . 'css/' . $frontend_file_name;
}
return $frontend_file_path;
}
/**
* Get Frontend File
*
* Returns a frontend file instance.
*
* @since 3.5.0
* @access public
*
* @param string $frontend_file_name
* @param string $file_prefix
* @param string $template_file_path
*
* @return FrontendFile
*/
public function get_frontend_file( $frontend_file_name, $file_prefix = 'custom-', $template_file_path = '' ) {
static $cached_frontend_files = [];
$file_name = $file_prefix . $frontend_file_name;
if ( isset( $cached_frontend_files[ $file_name ] ) ) {
return $cached_frontend_files[ $file_name ];
}
if ( ! $template_file_path ) {
$template_file_path = Breakpoints_Manager::get_stylesheet_templates_path() . $frontend_file_name;
}
$frontend_file = new FrontendFile( $file_name, $template_file_path );
$time = $frontend_file->get_meta( 'time' );
if ( ! $time ) {
$frontend_file->update();
}
$cached_frontend_files[ $file_name ] = $frontend_file;
return $frontend_file;
}
/**
* Enqueue assets conditionally.
*
* Enqueue all assets that were pre-enabled.
*
* @since 3.3.0
* @access private
*/
private function enqueue_conditional_assets() {
Plugin::$instance->assets_loader->enqueue_assets();
}
/**
* Elementor footer scripts and styles.
*
* Handle styles and scripts that are not printed in the header.
*
* Fired by `wp_footer` action.
*
* @since 1.0.11
* @access public
*/
public function wp_footer() {
if ( ! $this->_has_elementor_in_page ) {
return;
}
$this->enqueue_styles();
$this->enqueue_scripts();
$this->print_fonts_links();
}
/**
* @return array|array[]
*/
public function get_list_of_google_fonts_by_type(): array {
$google_fonts = [
'google' => [],
'early' => [],
];
foreach ( $this->fonts_to_enqueue as $key => $font ) {
$font_type = Fonts::get_font_type( $font );
switch ( $font_type ) {
case Fonts::GOOGLE:
$google_fonts['google'][] = $font;
break;
case Fonts::EARLYACCESS:
$google_fonts['early'][] = $font;
break;
case false:
$this->maybe_enqueue_icon_font( $font );
break;
default:
/**
* Print font links.
*
* Fires when Elementor frontend fonts are printed on the HEAD tag.
*
* The dynamic portion of the hook name, `$font_type`, refers to the font type.
*
* @since 2.0.0
*
* @param string $font Font name.
*/
do_action( "elementor/fonts/print_font_links/{$font_type}", $font );
}
}
$this->fonts_to_enqueue = [];
return $google_fonts;
}
/**
* Print fonts links.
*
* Enqueue all the frontend fonts by url.
*
* Fired by `wp_head` action.
*
* @since 1.9.4
* @access public
*/
public function print_fonts_links() {
/**
* Register font styles.
*
* Fires before fonts are processed, allowing add-ons to register
* proper stylesheets for their custom font types via the WordPress API.
*
* @since 3.29.0
*
* @param string[] $fonts_to_enqueue List of font families to be enqueued.
*/
do_action( 'elementor/fonts/register_styles', $this->fonts_to_enqueue );
$google_fonts = $this->get_list_of_google_fonts_by_type();
$this->enqueue_google_fonts( $google_fonts );
$this->enqueue_icon_fonts();
}
private function maybe_enqueue_icon_font( $icon_font_type ) {
if ( ! Icons_Manager::is_migration_allowed() ) {
return;
}
$icons_types = Icons_Manager::get_icon_manager_tabs();
if ( ! isset( $icons_types[ $icon_font_type ] ) ) {
return;
}
$icon_type = $icons_types[ $icon_font_type ];
if ( isset( $icon_type['url'] ) ) {
$this->icon_fonts_to_enqueue[ $icon_font_type ] = [ $icon_type['url'] ];
}
}
private function enqueue_icon_fonts() {
if ( empty( $this->icon_fonts_to_enqueue ) || ! Icons_Manager::is_migration_allowed() ) {
return;
}
foreach ( $this->icon_fonts_to_enqueue as $icon_type => $css_url ) {
wp_enqueue_style( 'elementor-icons-' . $icon_type );
$this->enqueued_icon_fonts[] = $css_url;
}
// Clear enqueued icons.
$this->icon_fonts_to_enqueue = [];
}
/**
* @param array $fonts Stable google fonts ($google_fonts['google']).
* @return string
*/
public function get_stable_google_fonts_url( array $fonts ): string {
foreach ( $fonts as &$font ) {
$font = str_replace( ' ', '+', $font ) . ':100,100italic,200,200italic,300,300italic,400,400italic,500,500italic,600,600italic,700,700italic,800,800italic,900,900italic';
}
// Defining a font-display type to google fonts.
$font_display_url_str = '&display=' . Fonts::get_font_display_setting();
$fonts_url = sprintf( 'https://fonts.googleapis.com/css?family=%1$s%2$s', implode( rawurlencode( '|' ), $fonts ), $font_display_url_str );
$subsets = [
'ru_RU' => 'cyrillic',
'bg_BG' => 'cyrillic',
'he_IL' => 'hebrew',
'el' => 'greek',
'vi' => 'vietnamese',
'uk' => 'cyrillic',
'cs_CZ' => 'latin-ext',
'ro_RO' => 'latin-ext',
'pl_PL' => 'latin-ext',
'hr_HR' => 'latin-ext',
'hu_HU' => 'latin-ext',
'sk_SK' => 'latin-ext',
'tr_TR' => 'latin-ext',
'lt_LT' => 'latin-ext',
];
/**
* Google font subsets.
*
* Filters the list of Google font subsets from which locale will be enqueued in frontend.
*
* @since 1.0.0
*
* @param array $subsets A list of font subsets.
*/
$subsets = apply_filters( 'elementor/frontend/google_font_subsets', $subsets );
$locale = get_locale();
if ( isset( $subsets[ $locale ] ) ) {
$fonts_url .= '&subset=' . $subsets[ $locale ];
}
return $fonts_url;