PluginProbe ʕ •ᴥ•ʔ
Elementor Website Builder – more than just a page builder / 3.16.0-dev1
Elementor Website Builder – more than just a page builder v3.16.0-dev1
4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 3.22.0-dev1 4.0.0-beta3 3.22.0-dev2 4.0.0-beta4 3.22.0-dev3 4.0.0-beta5 3.22.0-dev4 4.0.0-dev1 3.22.0-dev5 4.0.0-dev2 3.22.0-dev6 4.0.0-dev3 3.22.1 4.0.0-dev4 3.22.2 4.0.0-dev5 3.22.3 4.0.1 3.23.0 4.0.2 3.23.0-beta1 3.23.0-beta2 3.23.0-beta3 3.23.0-beta4 3.23.0-beta5 3.23.0-beta6 3.23.0-dev1 3.23.0-dev2 3.23.0-dev3 3.23.0-dev4 3.23.0-dev5 3.23.0-dev6 3.23.1 3.23.2 3.23.3 3.23.4 3.24.0 3.24.0-beta1 3.24.0-beta2 3.24.0-beta3 3.24.0-dev1 3.24.0-dev2 3.24.0-dev3 3.24.1 3.24.2 3.24.3 3.24.4 3.24.5 3.24.6 3.24.7 3.24.8 3.25.0 3.25.0-beta1 3.25.0-beta2 3.25.0-beta3 3.25.0-dev1 3.25.0-dev2 3.25.0-dev3 3.25.1 3.25.10 3.25.11 3.25.2 3.25.3 3.25.4 3.25.5 3.25.6 3.25.7 3.25.8 3.25.9 3.26.0 3.26.0-beta1 3.26.0-beta2 3.26.0-beta3 3.26.0-beta4 3.26.0-beta5 3.26.0-dev1 3.26.0-dev2 3.26.0-dev3 3.26.0-dev4 3.26.0-dev5 3.26.1 3.26.2 3.26.3 3.26.4 3.26.5 3.27.0 3.27.0-beta1 3.27.0-beta2 3.27.0-dev1 3.27.0-dev2 3.27.1 3.27.2 3.27.3 3.27.4 3.27.5 3.27.6 3.27.7 3.28.0 3.28.0-beta1 3.28.0-beta2 3.28.0-beta3 3.28.0-dev1 3.28.0-dev2 3.28.0-dev3 3.28.1 3.28.2 3.28.3 3.28.4 3.29.0 3.29.0-beta1 trunk 3.29.0-beta2 3.0.0 3.29.0-beta3 3.0.1 3.29.0-beta4 3.0.10 3.29.0-dev1 3.0.11 3.29.0-dev2 3.0.12 3.29.0-dev3 3.0.13 3.29.0-dev4 3.0.14 3.29.1 3.0.15 3.29.2 3.0.16 3.3.0 3.0.2 3.3.1 3.0.3 3.30.0 3.0.4 3.30.0-beta1 3.0.5 3.30.0-beta2 3.0.6 3.30.0-beta3 3.0.7 3.30.0-dev1 3.0.8 3.30.0-dev2 3.0.8.1 3.30.0-dev3 3.0.9 3.30.1 3.1.0 3.30.2 3.1.0-beta1 3.30.3 3.1.0-beta2 3.30.4 3.1.0-beta3 3.31.0 3.1.0-beta4 3.31.0-beta1 3.1.0-dev1 3.31.0-beta2 3.1.0-dev2 3.31.0-dev1 3.1.0-dev3 3.31.0-dev2 3.1.1 3.31.1 3.1.2 3.31.2 3.1.3 3.31.3 3.1.4 3.31.4 3.10.0 3.31.5 3.10.0-dev1 3.32.0 3.10.1 3.32.0-beta1 3.10.2 3.32.0-beta2 3.11.0 3.32.0-beta3 3.11.0-beta1 3.32.0-dev1 3.11.0-beta2 3.32.0-dev2 3.11.0-beta3 3.32.0-dev3 3.11.0-dev1 3.32.1 3.11.0-dev2 3.32.2 3.11.0-dev3 3.32.3 3.11.1 3.32.4 3.11.2 3.32.5 3.11.3 3.33.0 3.11.4 3.33.0-beta1 3.11.5 3.33.0-beta2 3.12.0 3.33.0-beta3 3.12.1 3.33.0-beta4 3.12.2 3.33.0-dev1 3.13.0 3.33.0-dev2 3.13.0-beta1 3.33.0-dev3 3.13.0-beta2 3.33.0-dev4 3.13.0-beta3 3.33.1 3.13.0-dev3 3.33.2 3.13.0-dev4 3.33.3 3.13.1 3.33.4 3.13.2 3.33.5 3.13.3 3.33.6 3.13.4 3.34.0 3.14.0 3.34.0-beta1 3.14.0-beta1 3.34.0-beta2 3.14.0-beta2 3.34.0-beta3 3.14.0-beta3 3.34.0-dev1 3.14.0-beta4 3.34.0-dev2 3.14.0-beta5 3.34.1 3.14.1 3.34.2 3.15.0 3.34.3 3.15.1 3.34.4 3.15.2 3.35.0 3.15.3 3.35.0-beta1 3.16.0 3.35.0-beta2 3.16.0-beta3 3.35.0-beta3 3.16.0-beta4 3.35.0-beta4 3.16.0-dev1 3.35.0-dev1 3.16.0-dev2 3.35.0-dev2 3.16.1 3.35.0-dev3 3.16.2 3.35.0-dev4 3.16.3 3.35.1 3.16.4 3.35.2 3.16.5 3.35.3 3.16.6 3.35.4 3.17.0 3.35.5 3.17.0-dev2 3.35.6 3.17.0-dev3 3.35.7 3.17.0-dev4 3.35.8 3.17.1 3.35.9 3.17.2 3.4.0 3.17.3 3.4.0-dev7 3.18.0 3.4.0-dev8 3.18.0-beta1 3.4.0-dev9 3.18.0-beta2 3.4.1 3.18.0-beta3 3.4.2 3.18.0-beta4 3.4.3 3.18.0-dev1 3.4.4 3.18.1 3.4.5 3.18.2 3.4.6 3.18.3 3.4.7 3.19.0 3.4.8 3.19.0-beta1 3.5.0 3.19.0-beta2 3.5.0-beta1 3.19.0-beta3 3.5.0-beta2 3.19.0-beta4 3.5.0-beta3 3.19.0-beta5 3.5.0-beta4 3.19.0-beta6 3.5.0-beta5 3.19.0-dev1 3.5.0-beta7 3.19.0-dev2 3.5.0-beta8 3.19.0-dev3 3.5.0-dev8 3.19.0-dev4 3.5.0-dev9 3.19.0-dev5 3.5.1 3.19.0-dev6 3.5.2 3.19.1 3.5.3 3.19.2 3.5.4 3.19.3 3.5.5 3.19.4 3.5.6 3.2.0 3.6.0 3.2.1 3.6.0-beta1 3.2.2 3.6.0-beta2 3.2.3 3.6.0-beta3 3.2.4 3.6.0-beta4 3.2.5 3.6.0-beta5 3.20.0 3.6.0-dev1 3.20.0-beta1 3.6.0-dev10 3.20.0-beta2 3.6.1 3.20.0-beta3 3.6.2 3.20.0-beta4 3.6.3 3.20.0-dev1 3.6.4 3.20.0-dev2 3.6.5 3.20.0-dev3 3.6.6 3.20.0-dev4 3.6.7 3.20.1 3.6.8 3.20.2 3.7.0 3.20.3 3.7.0-beta1 3.20.4 3.7.0-beta2 3.21.0 3.7.0-beta3 3.21.0-beta1 3.7.0-beta4 3.21.0-beta2 3.7.0-dev1 3.21.0-beta3 3.7.1 3.21.0-dev1 3.7.2 3.21.0-dev2 3.7.3 3.21.0-dev3 3.7.4 3.21.1 3.7.5 3.21.2 3.7.6 3.21.3 3.7.7 3.21.4 3.7.8 3.21.5 3.8.0 3.21.6 3.8.0-beta1 3.21.7 3.8.0-beta2 3.21.8 3.8.0-beta3 3.22.0 3.8.1 3.22.0-beta1 3.9.0 3.22.0-beta2 3.9.1 3.22.0-beta3 3.9.2 3.22.0-beta4 4.0.0 3.22.0-beta5 4.0.0-beta1 3.22.0-beta6 4.0.0-beta2
elementor / includes / frontend.php
elementor / includes Last commit date
admin-templates 3 years ago base 2 years ago controls 2 years ago editor-templates 2 years ago elements 2 years ago interfaces 3 years ago libraries 3 years ago managers 2 years ago settings 2 years ago template-library 2 years ago widgets 2 years ago api.php 2 years ago autoloader.php 3 years ago beta-testers.php 3 years ago compatibility.php 3 years ago conditions.php 3 years ago db.php 2 years ago embed.php 3 years ago fonts.php 3 years ago frontend.php 2 years ago heartbeat.php 3 years ago maintenance-mode.php 3 years ago maintenance.php 3 years ago plugin.php 2 years ago preview.php 3 years ago rollback.php 3 years ago shapes.php 3 years ago stylesheet.php 3 years ago tracker.php 3 years ago user.php 3 years ago utils.php 2 years ago
frontend.php
1586 lines
1 <?php
2 namespace Elementor;
3
4 use Elementor\Core\Base\App;
5 use Elementor\Core\Frontend\Render_Mode_Manager;
6 use Elementor\Core\Responsive\Files\Frontend as FrontendFile;
7 use Elementor\Core\Files\CSS\Global_CSS;
8 use Elementor\Core\Files\CSS\Post as Post_CSS;
9 use Elementor\Core\Files\CSS\Post_Preview;
10 use Elementor\Core\Responsive\Responsive;
11 use Elementor\Core\Settings\Manager as SettingsManager;
12 use Elementor\Core\Breakpoints\Manager as Breakpoints_Manager;
13
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit; // Exit if accessed directly.
16 }
17
18 /**
19 * Elementor frontend.
20 *
21 * Elementor frontend handler class is responsible for initializing Elementor in
22 * the frontend.
23 *
24 * @since 1.0.0
25 */
26 class Frontend extends App {
27
28 /**
29 * The priority of the content filter.
30 */
31 const THE_CONTENT_FILTER_PRIORITY = 9;
32
33 /**
34 * Post ID.
35 *
36 * Holds the ID of the current post.
37 *
38 * @access private
39 *
40 * @var int Post ID.
41 */
42 private $post_id;
43
44 /**
45 * Fonts to enqueue
46 *
47 * Holds the list of fonts that are being used in the current page.
48 *
49 * @since 1.9.4
50 * @access public
51 *
52 * @var array Used fonts. Default is an empty array.
53 */
54 public $fonts_to_enqueue = [];
55
56 /**
57 * Holds the class that respond to manage the render mode.
58 *
59 * @var Render_Mode_Manager
60 */
61 public $render_mode_manager;
62
63 /**
64 * Registered fonts.
65 *
66 * Holds the list of enqueued fonts in the current page.
67 *
68 * @since 1.0.0
69 * @access private
70 *
71 * @var array Registered fonts. Default is an empty array.
72 */
73 private $registered_fonts = [];
74
75 /**
76 * Icon Fonts to enqueue
77 *
78 * Holds the list of Icon fonts that are being used in the current page.
79 *
80 * @since 2.4.0
81 * @access private
82 *
83 * @var array Used icon fonts. Default is an empty array.
84 */
85 private $icon_fonts_to_enqueue = [];
86
87 /**
88 * Enqueue Icon Fonts
89 *
90 * Holds the list of Icon fonts already enqueued in the current page.
91 *
92 * @since 2.4.0
93 * @access private
94 *
95 * @var array enqueued icon fonts. Default is an empty array.
96 */
97 private $enqueued_icon_fonts = [];
98
99 /**
100 * Whether the page is using Elementor.
101 *
102 * Used to determine whether the current page is using Elementor.
103 *
104 * @since 1.0.0
105 * @access private
106 *
107 * @var bool Whether Elementor is being used. Default is false.
108 */
109 private $_has_elementor_in_page = false;
110
111 /**
112 * Whether the excerpt is being called.
113 *
114 * Used to determine whether the call to `the_content()` came from `get_the_excerpt()`.
115 *
116 * @since 1.0.0
117 * @access private
118 *
119 * @var bool Whether the excerpt is being used. Default is false.
120 */
121 private $_is_excerpt = false;
122
123 /**
124 * Filters removed from the content.
125 *
126 * Hold the list of filters removed from `the_content()`. Used to hold the filters that
127 * conflicted with Elementor while Elementor process the content.
128 *
129 * @since 1.0.0
130 * @access private
131 *
132 * @var array Filters removed from the content. Default is an empty array.
133 */
134 private $content_removed_filters = [];
135
136 /**
137 * @var string[]
138 */
139 private $body_classes = [
140 'elementor-default',
141 ];
142
143 private $google_fonts_index = 0;
144
145 /**
146 * @var string
147 */
148 private $e_swiper_asset_path;
149
150 /**
151 * @var string
152 */
153 private $e_swiper_version;
154
155 /**
156 * Front End constructor.
157 *
158 * Initializing Elementor front end. Make sure we are not in admin, not and
159 * redirect from old URL structure of Elementor editor.
160 *
161 * @since 1.0.0
162 * @access public
163 */
164 public function __construct() {
165 // We don't need this class in admin side, but in AJAX requests.
166 if ( is_admin() && ! wp_doing_ajax() ) {
167 return;
168 }
169
170 add_action( 'template_redirect', [ $this, 'init_render_mode' ], -1 /* Before admin bar. */ );
171 add_action( 'template_redirect', [ $this, 'init' ] );
172 add_action( 'wp_enqueue_scripts', [ $this, 'register_scripts' ], 5 );
173 add_action( 'wp_enqueue_scripts', [ $this, 'register_styles' ], 5 );
174
175 $this->add_content_filter();
176 $this->init_swiper_settings();
177
178 // Hack to avoid enqueue post CSS while it's a `the_excerpt` call.
179 add_filter( 'get_the_excerpt', [ $this, 'start_excerpt_flag' ], 1 );
180 add_filter( 'get_the_excerpt', [ $this, 'end_excerpt_flag' ], 20 );
181 }
182
183 /**
184 * Get module name.
185 *
186 * Retrieve the module name.
187 *
188 * @since 2.3.0
189 * @access public
190 *
191 * @return string Module name.
192 */
193 public function get_name() {
194 return 'frontend';
195 }
196
197 /**
198 * Init render mode manager.
199 */
200 public function init_render_mode() {
201 if ( Plugin::$instance->editor->is_edit_mode() ) {
202 return;
203 }
204
205 $this->render_mode_manager = new Render_Mode_Manager();
206 }
207
208 /**
209 * Init.
210 *
211 * Initialize Elementor front end. Hooks the needed actions to run Elementor
212 * in the front end, including script and style registration.
213 *
214 * Fired by `template_redirect` action.
215 *
216 * @since 1.0.0
217 * @access public
218 */
219 public function init() {
220 if ( Plugin::$instance->editor->is_edit_mode() ) {
221 return;
222 }
223
224 add_filter( 'body_class', [ $this, 'body_class' ] );
225
226 if ( Plugin::$instance->preview->is_preview_mode() ) {
227 return;
228 }
229
230 if ( current_user_can( 'manage_options' ) ) {
231 Plugin::$instance->init_common();
232 }
233
234 $this->post_id = get_the_ID();
235
236 $document = Plugin::$instance->documents->get( $this->post_id );
237
238 if ( is_singular() && $document && $document->is_built_with_elementor() ) {
239 add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_styles' ] );
240 }
241
242 // Priority 7 to allow google fonts in header template to load in <head> tag
243 add_action( 'wp_head', [ $this, 'print_fonts_links' ], 7 );
244 add_action( 'wp_head', [ $this, 'print_google_fonts_preconnect_tag' ], 8 );
245 add_action( 'wp_head', [ $this, 'add_theme_color_meta_tag' ] );
246 add_action( 'wp_footer', [ $this, 'wp_footer' ] );
247 }
248
249 public function print_google_fonts_preconnect_tag() {
250 if ( 0 >= $this->google_fonts_index ) {
251 return;
252 }
253
254 echo '<link rel="preconnect" href="https://fonts.gstatic.com/" crossorigin>';
255 }
256
257 /**
258 * @since 2.0.12
259 * @access public
260 * @param string|array $class
261 */
262 public function add_body_class( $class ) {
263 if ( is_array( $class ) ) {
264 $this->body_classes = array_merge( $this->body_classes, $class );
265 } else {
266 $this->body_classes[] = $class;
267 }
268 }
269
270 /**
271 * Add Theme Color Meta Tag
272 *
273 * @since 3.0.0
274 * @access public
275 */
276 public function add_theme_color_meta_tag() {
277 $kit = Plugin::$instance->kits_manager->get_active_kit_for_frontend();
278 $mobile_theme_color = $kit->get_settings( 'mobile_browser_background' );
279
280 if ( ! empty( $mobile_theme_color ) ) {
281 ?>
282 <meta name="theme-color" content="<?php echo esc_attr( $mobile_theme_color ); ?>">
283 <?php
284 }
285 }
286
287 /**
288 * Body tag classes.
289 *
290 * Add new elementor classes to the body tag.
291 *
292 * Fired by `body_class` filter.
293 *
294 * @since 1.0.0
295 * @access public
296 *
297 * @param array $classes Optional. One or more classes to add to the body tag class list.
298 * Default is an empty array.
299 *
300 * @return array Body tag classes.
301 */
302 public function body_class( $classes = [] ) {
303 $classes = array_merge( $classes, $this->body_classes );
304
305 $id = get_the_ID();
306
307 $document = Plugin::$instance->documents->get( $id );
308
309 if ( is_singular() && $document && $document->is_built_with_elementor() ) {
310 $classes[] = 'elementor-page elementor-page-' . $id;
311 }
312
313 if ( Plugin::$instance->preview->is_preview_mode() ) {
314 $editor_preferences = SettingsManager::get_settings_managers( 'editorPreferences' );
315
316 $show_hidden_elements = $editor_preferences->get_model()->get_settings( 'show_hidden_elements' );
317
318 if ( 'yes' === $show_hidden_elements ) {
319 $classes[] = 'e-preview--show-hidden-elements';
320 }
321 }
322
323 return $classes;
324 }
325
326 /**
327 * Add content filter.
328 *
329 * Remove plain content and render the content generated by Elementor.
330 *
331 * @since 1.8.0
332 * @access public
333 */
334 public function add_content_filter() {
335 add_filter( 'the_content', [ $this, 'apply_builder_in_content' ], self::THE_CONTENT_FILTER_PRIORITY );
336 }
337
338 public function init_swiper_settings() {
339 $e_swiper_latest = Plugin::$instance->experiments->is_feature_active( 'e_swiper_latest' );
340 $this->e_swiper_asset_path = $e_swiper_latest ? 'assets/lib/swiper/v8/' : 'assets/lib/swiper/';
341 $this->e_swiper_version = $e_swiper_latest ? '8.4.5' : '5.3.6';
342 }
343
344 /**
345 * Remove content filter.
346 *
347 * When the Elementor generated content rendered, we remove the filter to prevent multiple
348 * accuracies. This way we make sure Elementor renders the content only once.
349 *
350 * @since 1.8.0
351 * @access public
352 */
353 public function remove_content_filter() {
354 remove_filter( 'the_content', [ $this, 'apply_builder_in_content' ], self::THE_CONTENT_FILTER_PRIORITY );
355 }
356
357 /**
358 * Registers scripts.
359 *
360 * Registers all the frontend scripts.
361 *
362 * Fired by `wp_enqueue_scripts` action.
363 *
364 * @since 1.2.1
365 * @access public
366 */
367 public function register_scripts() {
368 /**
369 * Before frontend register scripts.
370 *
371 * Fires before Elementor frontend scripts are registered.
372 *
373 * @since 1.2.1
374 */
375 do_action( 'elementor/frontend/before_register_scripts' );
376
377 wp_register_script(
378 'elementor-webpack-runtime',
379 $this->get_js_assets_url( 'webpack.runtime', 'assets/js/' ),
380 [],
381 ELEMENTOR_VERSION,
382 true
383 );
384
385 wp_register_script(
386 'elementor-frontend-modules',
387 $this->get_js_assets_url( 'frontend-modules' ),
388 [
389 'elementor-webpack-runtime',
390 'jquery',
391 ],
392 ELEMENTOR_VERSION,
393 true
394 );
395
396 wp_register_script(
397 'elementor-waypoints',
398 $this->get_js_assets_url( 'waypoints', 'assets/lib/waypoints/' ),
399 [
400 'jquery',
401 ],
402 '4.0.2',
403 true
404 );
405
406 wp_register_script(
407 'flatpickr',
408 $this->get_js_assets_url( 'flatpickr', 'assets/lib/flatpickr/' ),
409 [
410 'jquery',
411 ],
412 '4.1.4',
413 true
414 );
415
416 wp_register_script(
417 'imagesloaded',
418 $this->get_js_assets_url( 'imagesloaded', 'assets/lib/imagesloaded/' ),
419 [
420 'jquery',
421 ],
422 '4.1.0',
423 true
424 );
425
426 wp_register_script(
427 'jquery-numerator',
428 $this->get_js_assets_url( 'jquery-numerator', 'assets/lib/jquery-numerator/' ),
429 [
430 'jquery',
431 ],
432 '0.2.1',
433 true
434 );
435
436 wp_register_script(
437 'elementor-dialog',
438 $this->get_js_assets_url( 'dialog', 'assets/lib/dialog/' ),
439 [
440 'jquery-ui-position',
441 ],
442 '4.9.0',
443 true
444 );
445
446 wp_register_script(
447 'elementor-gallery',
448 $this->get_js_assets_url( 'e-gallery', 'assets/lib/e-gallery/js/' ),
449 [
450 'jquery',
451 ],
452 '1.2.0',
453 true
454 );
455
456 wp_register_script(
457 'share-link',
458 $this->get_js_assets_url( 'share-link', 'assets/lib/share-link/' ),
459 [
460 'jquery',
461 ],
462 ELEMENTOR_VERSION,
463 true
464 );
465
466 wp_register_script(
467 'elementor-frontend',
468 $this->get_js_assets_url( 'frontend' ),
469 $this->get_elementor_frontend_dependencies(),
470 ELEMENTOR_VERSION,
471 true
472 );
473
474 /**
475 * After frontend register scripts.
476 *
477 * Fires after Elementor frontend scripts are registered.
478 *
479 * @since 1.2.1
480 */
481 do_action( 'elementor/frontend/after_register_scripts' );
482 }
483
484 /**
485 * Registers styles.
486 *
487 * Registers all the frontend styles.
488 *
489 * Fired by `wp_enqueue_scripts` action.
490 *
491 * @since 1.2.0
492 * @access public
493 */
494 public function register_styles() {
495 /**
496 * Before frontend register styles.
497 *
498 * Fires before Elementor frontend styles are registered.
499 *
500 * @since 1.2.0
501 */
502 do_action( 'elementor/frontend/before_register_styles' );
503
504 wp_register_style(
505 'font-awesome',
506 $this->get_css_assets_url( 'font-awesome', 'assets/lib/font-awesome/css/' ),
507 [],
508 '4.7.0'
509 );
510
511 wp_register_style(
512 'elementor-icons',
513 $this->get_css_assets_url( 'elementor-icons', 'assets/lib/eicons/css/' ),
514 [],
515 Icons_Manager::ELEMENTOR_ICONS_VERSION
516 );
517
518 wp_register_style(
519 'flatpickr',
520 $this->get_css_assets_url( 'flatpickr', 'assets/lib/flatpickr/' ),
521 [],
522 '4.1.4'
523 );
524
525 wp_register_style(
526 'elementor-gallery',
527 $this->get_css_assets_url( 'e-gallery', 'assets/lib/e-gallery/css/' ),
528 [],
529 '1.2.0'
530 );
531
532 $min_suffix = Utils::is_script_debug() ? '' : '.min';
533
534 $direction_suffix = is_rtl() ? '-rtl' : '';
535
536 $frontend_base_file_name = $this->is_optimized_css_mode() ? 'frontend-lite' : 'frontend';
537
538 $frontend_file_name = $frontend_base_file_name . $direction_suffix . $min_suffix . '.css';
539
540 $frontend_dependencies = [];
541
542 $has_custom_breakpoints = Plugin::$instance->breakpoints->has_custom_breakpoints();
543
544 if ( ! Plugin::$instance->experiments->is_feature_active( 'e_dom_optimization' ) ) {
545 // If The Dom Optimization feature is disabled, register the legacy CSS
546 wp_register_style(
547 'elementor-frontend-legacy',
548 $this->get_frontend_file_url( 'frontend-legacy' . $direction_suffix . $min_suffix . '.css', $has_custom_breakpoints ),
549 [],
550 ELEMENTOR_VERSION
551 );
552
553 $frontend_dependencies[] = 'elementor-frontend-legacy';
554 }
555
556 wp_register_style(
557 'elementor-frontend',
558 $this->get_frontend_file_url( $frontend_file_name, $has_custom_breakpoints ),
559 $frontend_dependencies,
560 $has_custom_breakpoints ? null : ELEMENTOR_VERSION
561 );
562
563 wp_register_style(
564 'swiper',
565 $this->get_css_assets_url( 'swiper', $this->e_swiper_asset_path . 'css/' ),
566 [],
567 $this->e_swiper_version
568 );
569
570 /**
571 * After frontend register styles.
572 *
573 * Fires after Elementor frontend styles are registered.
574 *
575 * @since 1.2.0
576 */
577 do_action( 'elementor/frontend/after_register_styles' );
578 }
579
580 /**
581 * Enqueue scripts.
582 *
583 * Enqueue all the frontend scripts.
584 *
585 * @since 1.0.0
586 * @access public
587 */
588 public function enqueue_scripts() {
589 /**
590 * Before frontend enqueue scripts.
591 *
592 * Fires before Elementor frontend scripts are enqueued.
593 *
594 * @since 1.0.0
595 */
596 do_action( 'elementor/frontend/before_enqueue_scripts' );
597
598 wp_enqueue_script( 'elementor-frontend' );
599
600 if ( ! $this->is_improved_assets_loading() ) {
601 wp_enqueue_script(
602 'preloaded-modules',
603 $this->get_js_assets_url( 'preloaded-modules', 'assets/js/' ),
604 [
605 'elementor-frontend',
606 ],
607 ELEMENTOR_VERSION,
608 true
609 );
610 }
611
612 $this->print_config();
613
614 $this->enqueue_conditional_assets();
615
616 /**
617 * After frontend enqueue scripts.
618 *
619 * Fires after Elementor frontend scripts are enqueued.
620 *
621 * @since 1.0.0
622 */
623 do_action( 'elementor/frontend/after_enqueue_scripts' );
624 }
625
626 /**
627 * Enqueue styles.
628 *
629 * Enqueue all the frontend styles.
630 *
631 * Fired by `wp_enqueue_scripts` action.
632 *
633 * @since 1.0.0
634 * @access public
635 */
636 public function enqueue_styles() {
637 static $is_enqueue_styles_already_triggered;
638
639 if ( ! $is_enqueue_styles_already_triggered ) {
640 $is_enqueue_styles_already_triggered = true;
641
642 /**
643 * Before frontend styles enqueued.
644 *
645 * Fires before Elementor frontend styles are enqueued.
646 *
647 * @since 1.0.0
648 */
649 do_action( 'elementor/frontend/before_enqueue_styles' );
650
651 // The e-icons are needed in preview mode for the editor icons (plus-icon for new section, folder-icon for the templates library etc.).
652 if ( ! Plugin::$instance->experiments->is_feature_active( 'e_font_icon_svg' ) || Plugin::$instance->preview->is_preview_mode() ) {
653 wp_enqueue_style( 'elementor-icons' );
654 }
655
656 wp_enqueue_style( 'elementor-frontend' );
657
658 wp_enqueue_style( 'swiper' );
659
660 /**
661 * After frontend styles enqueued.
662 *
663 * Fires after Elementor frontend styles are enqueued.
664 *
665 * @since 1.0.0
666 */
667 do_action( 'elementor/frontend/after_enqueue_styles' );
668
669 if ( ! Plugin::$instance->preview->is_preview_mode() ) {
670 $this->parse_global_css_code();
671
672 $post_id = get_the_ID();
673 // Check $post_id for virtual pages. check is singular because the $post_id is set to the first post on archive pages.
674 if ( $post_id && is_singular() ) {
675 $css_file = Post_CSS::create( get_the_ID() );
676 $css_file->enqueue();
677 }
678 }
679 }
680 }
681
682 /**
683 * Get Frontend File URL
684 *
685 * Returns the URL for the CSS file to be loaded in the front end. If requested via the second parameter, a custom
686 * file is generated based on a passed template file name. Otherwise, the URL for the default CSS file is returned.
687 *
688 * @since 3.4.5
689 *
690 * @access public
691 *
692 * @param string $frontend_file_name
693 * @param boolean $custom_file
694 *
695 * @return string frontend file URL
696 */
697 public function get_frontend_file_url( $frontend_file_name, $custom_file ) {
698 if ( $custom_file ) {
699 $frontend_file = $this->get_frontend_file( $frontend_file_name );
700
701 $frontend_file_url = $frontend_file->get_url();
702 } else {
703 $frontend_file_url = ELEMENTOR_ASSETS_URL . 'css/' . $frontend_file_name;
704 }
705
706 return $frontend_file_url;
707 }
708
709 /**
710 * Get Frontend File Path
711 *
712 * Returns the path for the CSS file to be loaded in the front end. If requested via the second parameter, a custom
713 * file is generated based on a passed template file name. Otherwise, the path for the default CSS file is returned.
714 *
715 * @since 3.5.0
716 * @access public
717 *
718 * @param string $frontend_file_name
719 * @param boolean $custom_file
720 *
721 * @return string frontend file path
722 */
723 public function get_frontend_file_path( $frontend_file_name, $custom_file ) {
724 if ( $custom_file ) {
725 $frontend_file = $this->get_frontend_file( $frontend_file_name );
726
727 $frontend_file_path = $frontend_file->get_path();
728 } else {
729 $frontend_file_path = ELEMENTOR_ASSETS_PATH . 'css/' . $frontend_file_name;
730 }
731
732 return $frontend_file_path;
733 }
734
735 /**
736 * Get Frontend File
737 *
738 * Returns a frontend file instance.
739 *
740 * @since 3.5.0
741 * @access public
742 *
743 * @param string $frontend_file_name
744 * @param string $file_prefix
745 * @param string $template_file_path
746 *
747 * @return FrontendFile
748 */
749 public function get_frontend_file( $frontend_file_name, $file_prefix = 'custom-', $template_file_path = '' ) {
750 static $cached_frontend_files = [];
751
752 $file_name = $file_prefix . $frontend_file_name;
753
754 if ( isset( $cached_frontend_files[ $file_name ] ) ) {
755 return $cached_frontend_files[ $file_name ];
756 }
757
758 if ( ! $template_file_path ) {
759 $template_file_path = Breakpoints_Manager::get_stylesheet_templates_path() . $frontend_file_name;
760 }
761
762 $frontend_file = new FrontendFile( $file_name, $template_file_path );
763
764 $time = $frontend_file->get_meta( 'time' );
765
766 if ( ! $time ) {
767 $frontend_file->update();
768 }
769
770 $cached_frontend_files[ $file_name ] = $frontend_file;
771
772 return $frontend_file;
773 }
774
775 /**
776 * Enqueue assets conditionally.
777 *
778 * Enqueue all assets that were pre-enabled.
779 *
780 * @since 3.3.0
781 * @access private
782 */
783 private function enqueue_conditional_assets() {
784 Plugin::$instance->assets_loader->enqueue_assets();
785 }
786
787 /**
788 * Elementor footer scripts and styles.
789 *
790 * Handle styles and scripts that are not printed in the header.
791 *
792 * Fired by `wp_footer` action.
793 *
794 * @since 1.0.11
795 * @access public
796 */
797 public function wp_footer() {
798 if ( ! $this->_has_elementor_in_page ) {
799 return;
800 }
801
802 $this->enqueue_styles();
803 $this->enqueue_scripts();
804
805 $this->print_fonts_links();
806 }
807
808 /**
809 * @return array|array[]
810 */
811 public function get_list_of_google_fonts_by_type(): array {
812 $google_fonts = [
813 'google' => [],
814 'early' => [],
815 ];
816
817 foreach ( $this->fonts_to_enqueue as $key => $font ) {
818 $font_type = Fonts::get_font_type( $font );
819
820 switch ( $font_type ) {
821 case Fonts::GOOGLE:
822 $google_fonts['google'][] = $font;
823 break;
824
825 case Fonts::EARLYACCESS:
826 $google_fonts['early'][] = $font;
827 break;
828
829 case false:
830 $this->maybe_enqueue_icon_font( $font );
831 break;
832 default:
833 /**
834 * Print font links.
835 *
836 * Fires when Elementor frontend fonts are printed on the HEAD tag.
837 *
838 * The dynamic portion of the hook name, `$font_type`, refers to the font type.
839 *
840 * @since 2.0.0
841 *
842 * @param string $font Font name.
843 */
844 do_action( "elementor/fonts/print_font_links/{$font_type}", $font );
845 }
846 }
847 $this->fonts_to_enqueue = [];
848
849 return $google_fonts;
850 }
851
852 /**
853 * Print fonts links.
854 *
855 * Enqueue all the frontend fonts by url.
856 *
857 * Fired by `wp_head` action.
858 *
859 * @since 1.9.4
860 * @access public
861 */
862 public function print_fonts_links() {
863 $google_fonts = $this->get_list_of_google_fonts_by_type();
864
865 $this->enqueue_google_fonts( $google_fonts );
866 $this->enqueue_icon_fonts();
867 }
868
869 private function maybe_enqueue_icon_font( $icon_font_type ) {
870 if ( ! Icons_Manager::is_migration_allowed() ) {
871 return;
872 }
873
874 $icons_types = Icons_Manager::get_icon_manager_tabs();
875 if ( ! isset( $icons_types[ $icon_font_type ] ) ) {
876 return;
877 }
878
879 $icon_type = $icons_types[ $icon_font_type ];
880 if ( isset( $icon_type['url'] ) ) {
881 $this->icon_fonts_to_enqueue[ $icon_font_type ] = [ $icon_type['url'] ];
882 }
883 }
884
885 private function enqueue_icon_fonts() {
886 if ( empty( $this->icon_fonts_to_enqueue ) || ! Icons_Manager::is_migration_allowed() ) {
887 return;
888 }
889
890 foreach ( $this->icon_fonts_to_enqueue as $icon_type => $css_url ) {
891 wp_enqueue_style( 'elementor-icons-' . $icon_type );
892 $this->enqueued_icon_fonts[] = $css_url;
893 }
894
895 //clear enqueued icons
896 $this->icon_fonts_to_enqueue = [];
897 }
898
899 /**
900 * @param array $fonts Stable google fonts ($google_fonts['google']).
901 * @return string
902 */
903 public function get_stable_google_fonts_url( array $fonts ): string {
904 foreach ( $fonts as &$font ) {
905 $font = str_replace( ' ', '+', $font ) . ':100,100italic,200,200italic,300,300italic,400,400italic,500,500italic,600,600italic,700,700italic,800,800italic,900,900italic';
906 }
907
908 // Defining a font-display type to google fonts.
909 $font_display_url_str = '&display=' . Fonts::get_font_display_setting();
910
911 $fonts_url = sprintf( 'https://fonts.googleapis.com/css?family=%1$s%2$s', implode( rawurlencode( '|' ), $fonts ), $font_display_url_str );
912
913 $subsets = [
914 'ru_RU' => 'cyrillic',
915 'bg_BG' => 'cyrillic',
916 'he_IL' => 'hebrew',
917 'el' => 'greek',
918 'vi' => 'vietnamese',
919 'uk' => 'cyrillic',
920 'cs_CZ' => 'latin-ext',
921 'ro_RO' => 'latin-ext',
922 'pl_PL' => 'latin-ext',
923 'hr_HR' => 'latin-ext',
924 'hu_HU' => 'latin-ext',
925 'sk_SK' => 'latin-ext',
926 'tr_TR' => 'latin-ext',
927 'lt_LT' => 'latin-ext',
928 ];
929
930 /**
931 * Google font subsets.
932 *
933 * Filters the list of Google font subsets from which locale will be enqueued in frontend.
934 *
935 * @since 1.0.0
936 *
937 * @param array $subsets A list of font subsets.
938 */
939 $subsets = apply_filters( 'elementor/frontend/google_font_subsets', $subsets );
940
941 $locale = get_locale();
942
943 if ( isset( $subsets[ $locale ] ) ) {
944 $fonts_url .= '&subset=' . $subsets[ $locale ];
945 }
946
947 return $fonts_url;
948 }
949
950 /**
951 * @param array $fonts Early Access google fonts ($google_fonts['early']).
952 * @return array
953 */
954 public function get_early_access_google_font_urls( array $fonts ): array {
955 $font_urls = [];
956
957 foreach ( $fonts as $font ) {
958 $font_urls[] = sprintf( 'https://fonts.googleapis.com/earlyaccess/%s.css', strtolower( str_replace( ' ', '', $font ) ) );
959 }
960
961 return $font_urls;
962 }
963
964 /**
965 * Print Google fonts.
966 *
967 * Enqueue all the frontend Google fonts.
968 *
969 * Fired by `wp_head` action.
970 *
971 * @since 1.0.0
972 * @access private
973 *
974 * @param array $google_fonts Optional. Google fonts to print in the frontend.
975 * Default is an empty array.
976 */
977 private function enqueue_google_fonts( $google_fonts = [] ) {
978 $print_google_fonts = Fonts::is_google_fonts_enabled();
979
980 /**
981 * Print frontend google fonts.
982 *
983 * Filters whether to enqueue Google fonts in the frontend.
984 *
985 * @since 1.0.0
986 *
987 * @param bool $print_google_fonts Whether to enqueue Google fonts. Default is true.
988 */
989 $print_google_fonts = apply_filters( 'elementor/frontend/print_google_fonts', $print_google_fonts );
990
991 if ( ! $print_google_fonts ) {
992 return;
993 }
994
995 // Print used fonts
996 if ( ! empty( $google_fonts['google'] ) ) {
997 $this->google_fonts_index++;
998
999 $fonts_url = $this->get_stable_google_fonts_url( $google_fonts['google'] );
1000
1001 wp_enqueue_style( 'google-fonts-' . $this->google_fonts_index, $fonts_url ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
1002 }
1003
1004 if ( ! empty( $google_fonts['early'] ) ) {
1005 $early_access_font_urls = $this->get_early_access_google_font_urls( $google_fonts['early'] );
1006
1007 foreach ( $early_access_font_urls as $ea_font_url ) {
1008 $this->google_fonts_index++;
1009
1010 //printf( '<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/earlyaccess/%s.css">', strtolower( str_replace( ' ', '', $current_font ) ) );
1011
1012 wp_enqueue_style( 'google-earlyaccess-' . $this->google_fonts_index, $ea_font_url ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
1013 }
1014 }
1015
1016 }
1017
1018 /**
1019 * Enqueue fonts.
1020 *
1021 * Enqueue all the frontend fonts.
1022 *
1023 * @since 1.2.0
1024 * @access public
1025 *
1026 * @param array $font Fonts to enqueue in the frontend.
1027 */
1028 public function enqueue_font( $font ) {
1029 if ( in_array( $font, $this->registered_fonts ) ) {
1030 return;
1031 }
1032
1033 $this->fonts_to_enqueue[] = $font;
1034 $this->registered_fonts[] = $font;
1035 }
1036
1037 /**
1038 * Parse global CSS.
1039 *
1040 * Enqueue the global CSS file.
1041 *
1042 * @since 1.2.0
1043 * @access protected
1044 */
1045 protected function parse_global_css_code() {
1046 $scheme_css_file = Global_CSS::create( 'global.css' );
1047
1048 $scheme_css_file->enqueue();
1049 }
1050
1051 /**
1052 * Apply builder in content.
1053 *
1054 * Used to apply the Elementor page editor on the post content.
1055 *
1056 * @since 1.0.0
1057 * @access public
1058 *
1059 * @param string $content The post content.
1060 *
1061 * @return string The post content.
1062 */
1063 public function apply_builder_in_content( $content ) {
1064 $this->restore_content_filters();
1065
1066 if ( Plugin::$instance->preview->is_preview_mode() || $this->_is_excerpt ) {
1067 return $content;
1068 }
1069
1070 // Remove the filter itself in order to allow other `the_content` in the elements
1071 $this->remove_content_filter();
1072
1073 $post_id = get_the_ID();
1074 $builder_content = $this->get_builder_content( $post_id );
1075
1076 if ( ! empty( $builder_content ) ) {
1077 $content = $builder_content;
1078 $this->remove_content_filters();
1079 }
1080
1081 // Add the filter again for other `the_content` calls
1082 $this->add_content_filter();
1083
1084 return $content;
1085 }
1086
1087 /**
1088 * Retrieve builder content.
1089 *
1090 * Used to render and return the post content with all the Elementor elements.
1091 *
1092 * Note that this method is an internal method, please use `get_builder_content_for_display()`.
1093 *
1094 * @since 1.0.0
1095 * @access public
1096 *
1097 * @param int $post_id The post ID.
1098 * @param bool $with_css Optional. Whether to retrieve the content with CSS
1099 * or not. Default is false.
1100 *
1101 * @return string The post content.
1102 */
1103 public function get_builder_content( $post_id, $with_css = false ) {
1104 if ( post_password_required( $post_id ) ) {
1105 return '';
1106 }
1107
1108 $document = Plugin::$instance->documents->get_doc_for_frontend( $post_id );
1109
1110 if ( ! $document || ! $document->is_built_with_elementor() ) {
1111 return '';
1112 }
1113
1114 // Change the current post, so widgets can use `documents->get_current`.
1115 Plugin::$instance->documents->switch_to_document( $document );
1116
1117 $data = $document->get_elements_data();
1118
1119 /**
1120 * Frontend builder content data.
1121 *
1122 * Filters the builder content in the frontend.
1123 *
1124 * @since 1.0.0
1125 *
1126 * @param array $data The builder content.
1127 * @param int $post_id The post ID.
1128 */
1129 $data = apply_filters( 'elementor/frontend/builder_content_data', $data, $post_id );
1130
1131 do_action( 'elementor/frontend/before_get_builder_content', $document, $this->_is_excerpt );
1132
1133 if ( empty( $data ) ) {
1134 Plugin::$instance->documents->restore_document();
1135
1136 return '';
1137 }
1138
1139 if ( ! $this->_is_excerpt ) {
1140 if ( $document->is_autosave() ) {
1141 $css_file = Post_Preview::create( $document->get_post()->ID );
1142 } else {
1143 $css_file = Post_CSS::create( $post_id );
1144 }
1145
1146 /**
1147 * Builder Content - Before Enqueue CSS File
1148 *
1149 * Allows intervening with a document's CSS file before it is enqueued.
1150 *
1151 * @param $css_file Post_CSS|Post_Preview
1152 */
1153 $css_file = apply_filters( 'elementor/frontend/builder_content/before_enqueue_css_file', $css_file );
1154
1155 $css_file->enqueue();
1156 }
1157
1158 ob_start();
1159
1160 // Handle JS and Customizer requests, with CSS inline.
1161 if ( is_customize_preview() || wp_doing_ajax() ) {
1162 $with_css = true;
1163 }
1164
1165 /**
1166 * Builder Content - With CSS
1167 *
1168 * Allows overriding the `$with_css` parameter which is a factor in determining whether to print the document's
1169 * CSS and font links inline in a `style` tag above the document's markup.
1170 *
1171 * @param $with_css boolean
1172 */
1173 $with_css = apply_filters( 'elementor/frontend/builder_content/before_print_css', $with_css );
1174
1175 if ( ! empty( $css_file ) && $with_css ) {
1176 $css_file->print_css();
1177 }
1178
1179 $document->print_elements_with_wrapper( $data );
1180
1181 $content = ob_get_clean();
1182
1183 $content = $this->process_more_tag( $content );
1184
1185 /**
1186 * Frontend content.
1187 *
1188 * Filters the content in the frontend.
1189 *
1190 * @since 1.0.0
1191 *
1192 * @param string $content The content.
1193 */
1194 $content = apply_filters( 'elementor/frontend/the_content', $content );
1195
1196 if ( ! empty( $content ) ) {
1197 $this->_has_elementor_in_page = true;
1198 }
1199
1200 Plugin::$instance->documents->restore_document();
1201
1202 // BC
1203 // TODO: use Deprecation::do_deprecated_action() in 3.1.0
1204 do_action( 'elementor/frontend/get_builder_content', $document, $this->_is_excerpt, $with_css );
1205
1206 return $content;
1207 }
1208
1209 /**
1210 * Retrieve builder content for display.
1211 *
1212 * Used to render and return the post content with all the Elementor elements.
1213 *
1214 * @since 1.0.0
1215 * @access public
1216 *
1217 * @param int $post_id The post ID.
1218 *
1219 * @param bool $with_css Optional. Whether to retrieve the content with CSS
1220 * or not. Default is false.
1221 *
1222 * @return string The post content.
1223 */
1224 public function get_builder_content_for_display( $post_id, $with_css = false ) {
1225 if ( ! get_post( $post_id ) ) {
1226 return '';
1227 }
1228
1229 $editor = Plugin::$instance->editor;
1230
1231 // Avoid recursion
1232 if ( get_the_ID() === (int) $post_id ) {
1233 $content = '';
1234 if ( $editor->is_edit_mode() ) {
1235 $content = '<div class="elementor-alert elementor-alert-danger">' . esc_html__( 'Invalid Data: The Template ID cannot be the same as the currently edited template. Please choose a different one.', 'elementor' ) . '</div>';
1236 }
1237
1238 return $content;
1239 }
1240
1241 // Set edit mode as false, so don't render settings and etc. use the $is_edit_mode to indicate if we need the CSS inline
1242 $is_edit_mode = $editor->is_edit_mode();
1243 $editor->set_edit_mode( false );
1244
1245 $with_css = $with_css ? true : $is_edit_mode;
1246
1247 $content = $this->get_builder_content( $post_id, $with_css );
1248
1249 // Restore edit mode state
1250 Plugin::$instance->editor->set_edit_mode( $is_edit_mode );
1251
1252 return $content;
1253 }
1254
1255 /**
1256 * Start excerpt flag.
1257 *
1258 * Flags when `the_excerpt` is called. Used to avoid enqueueing CSS in the excerpt.
1259 *
1260 * @since 1.4.3
1261 * @access public
1262 *
1263 * @param string $excerpt The post excerpt.
1264 *
1265 * @return string The post excerpt.
1266 */
1267 public function start_excerpt_flag( $excerpt ) {
1268 $this->_is_excerpt = true;
1269 return $excerpt;
1270 }
1271
1272 /**
1273 * End excerpt flag.
1274 *
1275 * Flags when `the_excerpt` call ended.
1276 *
1277 * @since 1.4.3
1278 * @access public
1279 *
1280 * @param string $excerpt The post excerpt.
1281 *
1282 * @return string The post excerpt.
1283 */
1284 public function end_excerpt_flag( $excerpt ) {
1285 $this->_is_excerpt = false;
1286 return $excerpt;
1287 }
1288
1289 /**
1290 * Remove content filters.
1291 *
1292 * Remove WordPress default filters that conflicted with Elementor.
1293 *
1294 * @since 1.5.0
1295 * @access public
1296 */
1297 public function remove_content_filters() {
1298 $filters = [
1299 'wpautop',
1300 'shortcode_unautop',
1301 'wptexturize',
1302 ];
1303
1304 foreach ( $filters as $filter ) {
1305 // Check if another plugin/theme do not already removed the filter.
1306 if ( has_filter( 'the_content', $filter ) ) {
1307 remove_filter( 'the_content', $filter );
1308 $this->content_removed_filters[] = $filter;
1309 }
1310 }
1311 }
1312
1313 /**
1314 * Has Elementor In Page
1315 *
1316 * Determine whether the current page is using Elementor.
1317 *
1318 * @since 2.0.9
1319 *
1320 * @access public
1321 * @return bool
1322 */
1323 public function has_elementor_in_page() {
1324 return $this->_has_elementor_in_page;
1325 }
1326
1327 public function create_action_hash( $action, array $settings = [] ) {
1328 return '#' . rawurlencode( sprintf( 'elementor-action:action=%1$s&settings=%2$s', $action, base64_encode( wp_json_encode( $settings ) ) ) );
1329 }
1330
1331 /**
1332 * Is the current render mode is static.
1333 *
1334 * @return bool
1335 */
1336 public function is_static_render_mode() {
1337 // The render mode manager is exists only in frontend,
1338 // so by default if it is not exist the method will return false.
1339 if ( ! $this->render_mode_manager ) {
1340 return false;
1341 }
1342
1343 return $this->render_mode_manager->get_current()->is_static();
1344 }
1345
1346 /**
1347 * Get Init Settings
1348 *
1349 * Used to define the default/initial settings of the object. Inheriting classes may implement this method to define
1350 * their own default/initial settings.
1351 *
1352 * @since 2.3.0
1353 *
1354 * @access protected
1355 * @return array
1356 */
1357 protected function get_init_settings() {
1358 $is_preview_mode = Plugin::$instance->preview->is_preview_mode( Plugin::$instance->preview->get_post_id() );
1359
1360 $active_experimental_features = Plugin::$instance->experiments->get_active_features();
1361
1362 $active_experimental_features = array_fill_keys( array_keys( $active_experimental_features ), true );
1363
1364 $assets_url = ELEMENTOR_ASSETS_URL;
1365
1366 /**
1367 * Frontend assets URL
1368 *
1369 * Filters Elementor frontend assets URL.
1370 *
1371 * @since 2.3.0
1372 *
1373 * @param string $assets_url The frontend assets URL. Default is ELEMENTOR_ASSETS_URL.
1374 */
1375 $assets_url = apply_filters( 'elementor/frontend/assets_url', $assets_url );
1376
1377 $settings = [
1378 'environmentMode' => [
1379 'edit' => $is_preview_mode,
1380 'wpPreview' => is_preview(),
1381 'isScriptDebug' => Utils::is_script_debug(),
1382 ],
1383 'i18n' => [
1384 'shareOnFacebook' => esc_html__( 'Share on Facebook', 'elementor' ),
1385 'shareOnTwitter' => esc_html__( 'Share on Twitter', 'elementor' ),
1386 'pinIt' => esc_html__( 'Pin it', 'elementor' ),
1387 'download' => esc_html__( 'Download', 'elementor' ),
1388 'downloadImage' => esc_html__( 'Download image', 'elementor' ),
1389 'fullscreen' => esc_html__( 'Fullscreen', 'elementor' ),
1390 'zoom' => esc_html__( 'Zoom', 'elementor' ),
1391 'share' => esc_html__( 'Share', 'elementor' ),
1392 'playVideo' => esc_html__( 'Play Video', 'elementor' ),
1393 'previous' => esc_html__( 'Previous', 'elementor' ),
1394 'next' => esc_html__( 'Next', 'elementor' ),
1395 'close' => esc_html__( 'Close', 'elementor' ),
1396 'a11yCarouselWrapperAriaLabel' => __( 'Carousel | Horizontal scrolling: Arrow Left & Right', 'elementor' ),
1397 'a11yCarouselPrevSlideMessage' => __( 'Previous slide', 'elementor' ),
1398 'a11yCarouselNextSlideMessage' => __( 'Next slide', 'elementor' ),
1399 'a11yCarouselFirstSlideMessage' => __( 'This is the first slide', 'elementor' ),
1400 'a11yCarouselLastSlideMessage' => __( 'This is the last slide', 'elementor' ),
1401 'a11yCarouselPaginationBulletMessage' => __( 'Go to slide', 'elementor' ),
1402 ],
1403 'is_rtl' => is_rtl(),
1404 // 'breakpoints' object is kept for BC.
1405 'breakpoints' => Responsive::get_breakpoints(),
1406 // 'responsive' contains the custom breakpoints config introduced in Elementor v3.2.0
1407 'responsive' => [
1408 'breakpoints' => Plugin::$instance->breakpoints->get_breakpoints_config(),
1409 ],
1410 'version' => ELEMENTOR_VERSION,
1411 'is_static' => $this->is_static_render_mode(),
1412 'experimentalFeatures' => $active_experimental_features,
1413 'urls' => [
1414 'assets' => $assets_url,
1415 ],
1416 'swiperClass' => Plugin::$instance->experiments->is_feature_active( 'e_swiper_latest' ) ? 'swiper' : 'swiper-container',
1417 ];
1418
1419 $settings['settings'] = SettingsManager::get_settings_frontend_config();
1420
1421 $kit = Plugin::$instance->kits_manager->get_active_kit_for_frontend();
1422 $settings['kit'] = $kit->get_frontend_settings();
1423
1424 if ( is_singular() ) {
1425 $post = get_post();
1426
1427 $title = Utils::urlencode_html_entities( wp_get_document_title() );
1428
1429 // Try to use the 'large' WP image size because the Pinterest share API
1430 // has problems accepting shares with large images sometimes, and the WP 'large' thumbnail is
1431 // the largest default WP image size that will probably not be changed in most sites
1432 $featured_image_url = get_the_post_thumbnail_url( null, 'large' );
1433
1434 // If the large size was nullified, use the full size which cannot be nullified/deleted
1435 if ( ! $featured_image_url ) {
1436 $featured_image_url = get_the_post_thumbnail_url( null, 'full' );
1437 }
1438
1439 $settings['post'] = [
1440 'id' => $post->ID,
1441 'title' => $title,
1442 'excerpt' => $post->post_excerpt,
1443 'featuredImage' => $featured_image_url,
1444 ];
1445 } else {
1446 $settings['post'] = [
1447 'id' => 0,
1448 'title' => wp_get_document_title(),
1449 'excerpt' => get_the_archive_description(),
1450 ];
1451 }
1452
1453 $empty_object = (object) [];
1454
1455 if ( $is_preview_mode ) {
1456 $settings['elements'] = [
1457 'data' => $empty_object,
1458 'editSettings' => $empty_object,
1459 'keys' => $empty_object,
1460 ];
1461 }
1462
1463 if ( is_user_logged_in() ) {
1464 $user = wp_get_current_user();
1465
1466 if ( ! empty( $user->roles ) ) {
1467 $settings['user'] = [
1468 'roles' => $user->roles,
1469 ];
1470 }
1471 }
1472
1473 return $settings;
1474 }
1475
1476 /**
1477 * Restore content filters.
1478 *
1479 * Restore removed WordPress filters that conflicted with Elementor.
1480 *
1481 * @since 1.5.0
1482 * @access public
1483 */
1484 public function restore_content_filters() {
1485 foreach ( $this->content_removed_filters as $filter ) {
1486 add_filter( 'the_content', $filter );
1487 }
1488
1489 $this->content_removed_filters = [];
1490 }
1491
1492 /**
1493 * Process More Tag
1494 *
1495 * Respect the native WP (<!--more-->) tag
1496 *
1497 * @access private
1498 * @since 2.0.4
1499 *
1500 * @param $content
1501 *
1502 * @return string
1503 */
1504 private function process_more_tag( $content ) {
1505 $post = get_post();
1506 $content = str_replace( '&lt;!--more--&gt;', '<!--more-->', $content );
1507 $parts = get_extended( $content );
1508 if ( empty( $parts['extended'] ) ) {
1509 return $content;
1510 }
1511
1512 if ( is_singular() ) {
1513 return $parts['main'] . '<div id="more-' . $post->ID . '"></div>' . $parts['extended'];
1514 }
1515
1516 if ( empty( $parts['more_text'] ) ) {
1517 $parts['more_text'] = esc_html__( '(more&hellip;)', 'elementor' );
1518 }
1519
1520 $more_link_text = sprintf(
1521 '<span aria-label="%1$s">%2$s</span>',
1522 sprintf(
1523 /* translators: %s: Current post name. */
1524 __( 'Continue reading %s', 'elementor' ),
1525 the_title_attribute( [
1526 'echo' => false,
1527 ] )
1528 ),
1529 $parts['more_text']
1530 );
1531
1532 $more_link = sprintf( ' <a href="%s#more-%s" class="more-link elementor-more-link">%s</a>', get_permalink(), $post->ID, $more_link_text );
1533
1534 /**
1535 * The content "more" link.
1536 *
1537 * Filters the "more" link displayed after the content.
1538 *
1539 * This hook can be used either to change the link syntax or to change the
1540 * text inside the link.
1541 *
1542 * @since 2.0.4
1543 *
1544 * @param string $more_link The more link.
1545 * @param string $more_link_text The text inside the more link.
1546 */
1547 $more_link = apply_filters( 'the_content_more_link', $more_link, $more_link_text );
1548
1549 return force_balance_tags( $parts['main'] ) . $more_link;
1550 }
1551
1552 private function is_improved_assets_loading() {
1553 return Plugin::$instance->experiments->is_feature_active( 'e_optimized_assets_loading' );
1554 }
1555
1556 private function get_elementor_frontend_dependencies() {
1557 $dependencies = [
1558 'elementor-frontend-modules',
1559 'elementor-waypoints',
1560 'jquery-ui-position',
1561 ];
1562
1563 if ( ! $this->is_improved_assets_loading() ) {
1564 wp_register_script(
1565 'swiper',
1566 $this->get_js_assets_url( 'swiper', $this->e_swiper_asset_path ),
1567 [],
1568 $this->e_swiper_version,
1569 true
1570 );
1571
1572 $dependencies[] = 'swiper';
1573 $dependencies[] = 'share-link';
1574 $dependencies[] = 'elementor-dialog';
1575 }
1576
1577 return $dependencies;
1578 }
1579
1580 private function is_optimized_css_mode() {
1581 $is_optimized_css_loading = Plugin::$instance->experiments->is_feature_active( 'e_optimized_css_loading' );
1582
1583 return ! Utils::is_script_debug() && $is_optimized_css_loading && ! Plugin::$instance->preview->is_preview_mode();
1584 }
1585 }
1586