PluginProbe ʕ •ᴥ•ʔ
Elementor Website Builder – more than just a page builder / 3.5.0-beta4
Elementor Website Builder – more than just a page builder v3.5.0-beta4
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 4 years ago base 4 years ago controls 4 years ago editor-templates 4 years ago elements 4 years ago interfaces 6 years ago libraries 5 years ago managers 4 years ago settings 4 years ago template-library 4 years ago widgets 4 years ago api.php 4 years ago autoloader.php 4 years ago beta-testers.php 6 years ago compatibility.php 4 years ago conditions.php 6 years ago db.php 5 years ago embed.php 4 years ago fonts.php 4 years ago frontend.php 4 years ago heartbeat.php 7 years ago maintenance-mode.php 4 years ago maintenance.php 4 years ago plugin.php 4 years ago preview.php 4 years ago rollback.php 4 years ago shapes.php 6 years ago stylesheet.php 4 years ago tracker.php 4 years ago user.php 4 years ago utils.php 4 years ago
frontend.php
1492 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 /**
144 * Front End constructor.
145 *
146 * Initializing Elementor front end. Make sure we are not in admin, not and
147 * redirect from old URL structure of Elementor editor.
148 *
149 * @since 1.0.0
150 * @access public
151 */
152 public function __construct() {
153 // We don't need this class in admin side, but in AJAX requests.
154 if ( is_admin() && ! wp_doing_ajax() ) {
155 return;
156 }
157
158 add_action( 'template_redirect', [ $this, 'init_render_mode' ], -1 /* Before admin bar. */ );
159 add_action( 'template_redirect', [ $this, 'init' ] );
160 add_action( 'wp_enqueue_scripts', [ $this, 'register_scripts' ], 5 );
161 add_action( 'wp_enqueue_scripts', [ $this, 'register_styles' ], 5 );
162
163 $this->add_content_filter();
164
165 // Hack to avoid enqueue post CSS while it's a `the_excerpt` call.
166 add_filter( 'get_the_excerpt', [ $this, 'start_excerpt_flag' ], 1 );
167 add_filter( 'get_the_excerpt', [ $this, 'end_excerpt_flag' ], 20 );
168 }
169
170 /**
171 * Get module name.
172 *
173 * Retrieve the module name.
174 *
175 * @since 2.3.0
176 * @access public
177 *
178 * @return string Module name.
179 */
180 public function get_name() {
181 return 'frontend';
182 }
183
184 /**
185 * Init render mode manager.
186 */
187 public function init_render_mode() {
188 if ( Plugin::$instance->editor->is_edit_mode() ) {
189 return;
190 }
191
192 $this->render_mode_manager = new Render_Mode_Manager();
193 }
194
195 /**
196 * Init.
197 *
198 * Initialize Elementor front end. Hooks the needed actions to run Elementor
199 * in the front end, including script and style registration.
200 *
201 * Fired by `template_redirect` action.
202 *
203 * @since 1.0.0
204 * @access public
205 */
206 public function init() {
207 if ( Plugin::$instance->editor->is_edit_mode() ) {
208 return;
209 }
210
211 add_filter( 'body_class', [ $this, 'body_class' ] );
212
213 if ( Plugin::$instance->preview->is_preview_mode() ) {
214 return;
215 }
216
217 if ( current_user_can( 'manage_options' ) ) {
218 Plugin::$instance->init_common();
219 }
220
221 $this->post_id = get_the_ID();
222
223 $document = Plugin::$instance->documents->get( $this->post_id );
224
225 if ( is_singular() && $document && $document->is_built_with_elementor() ) {
226 add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_styles' ] );
227 }
228
229 // Priority 7 to allow google fonts in header template to load in <head> tag
230 add_action( 'wp_head', [ $this, 'print_fonts_links' ], 7 );
231 add_action( 'wp_head', [ $this, 'add_theme_color_meta_tag' ] );
232 add_action( 'wp_footer', [ $this, 'wp_footer' ] );
233 }
234
235 /**
236 * @since 2.0.12
237 * @access public
238 * @param string|array $class
239 */
240 public function add_body_class( $class ) {
241 if ( is_array( $class ) ) {
242 $this->body_classes = array_merge( $this->body_classes, $class );
243 } else {
244 $this->body_classes[] = $class;
245 }
246 }
247
248 /**
249 * Add Theme Color Meta Tag
250 *
251 * @since 3.0.0
252 * @access public
253 */
254 public function add_theme_color_meta_tag() {
255 $kit = Plugin::$instance->kits_manager->get_active_kit_for_frontend();
256 $mobile_theme_color = $kit->get_settings( 'mobile_theme_color' );
257
258 if ( ! empty( $mobile_theme_color ) ) {
259 ?>
260 <meta name="theme-color" content="<?php echo esc_html( $mobile_theme_color ); ?>">
261 <?php
262 }
263 }
264
265 /**
266 * Body tag classes.
267 *
268 * Add new elementor classes to the body tag.
269 *
270 * Fired by `body_class` filter.
271 *
272 * @since 1.0.0
273 * @access public
274 *
275 * @param array $classes Optional. One or more classes to add to the body tag class list.
276 * Default is an empty array.
277 *
278 * @return array Body tag classes.
279 */
280 public function body_class( $classes = [] ) {
281 $classes = array_merge( $classes, $this->body_classes );
282
283 $id = get_the_ID();
284
285 $document = Plugin::$instance->documents->get( $id );
286
287 if ( is_singular() && $document && $document->is_built_with_elementor() ) {
288 $classes[] = 'elementor-page elementor-page-' . $id;
289 }
290
291 if ( Plugin::$instance->preview->is_preview_mode() ) {
292 $editor_preferences = SettingsManager::get_settings_managers( 'editorPreferences' );
293
294 $show_hidden_elements = $editor_preferences->get_model()->get_settings( 'show_hidden_elements' );
295
296 if ( 'yes' === $show_hidden_elements ) {
297 $classes[] = 'e-preview--show-hidden-elements';
298 }
299 }
300
301 return $classes;
302 }
303
304 /**
305 * Add content filter.
306 *
307 * Remove plain content and render the content generated by Elementor.
308 *
309 * @since 1.8.0
310 * @access public
311 */
312 public function add_content_filter() {
313 add_filter( 'the_content', [ $this, 'apply_builder_in_content' ], self::THE_CONTENT_FILTER_PRIORITY );
314 }
315
316 /**
317 * Remove content filter.
318 *
319 * When the Elementor generated content rendered, we remove the filter to prevent multiple
320 * accuracies. This way we make sure Elementor renders the content only once.
321 *
322 * @since 1.8.0
323 * @access public
324 */
325 public function remove_content_filter() {
326 remove_filter( 'the_content', [ $this, 'apply_builder_in_content' ], self::THE_CONTENT_FILTER_PRIORITY );
327 }
328
329 /**
330 * Registers scripts.
331 *
332 * Registers all the frontend scripts.
333 *
334 * Fired by `wp_enqueue_scripts` action.
335 *
336 * @since 1.2.1
337 * @access public
338 */
339 public function register_scripts() {
340 /**
341 * Before frontend register scripts.
342 *
343 * Fires before Elementor frontend scripts are registered.
344 *
345 * @since 1.2.1
346 */
347 do_action( 'elementor/frontend/before_register_scripts' );
348
349 wp_register_script(
350 'elementor-webpack-runtime',
351 $this->get_js_assets_url( 'webpack.runtime', 'assets/js/' ),
352 [],
353 ELEMENTOR_VERSION,
354 true
355 );
356
357 wp_register_script(
358 'elementor-frontend-modules',
359 $this->get_js_assets_url( 'frontend-modules' ),
360 [
361 'elementor-webpack-runtime',
362 'jquery',
363 ],
364 ELEMENTOR_VERSION,
365 true
366 );
367
368 wp_register_script(
369 'elementor-waypoints',
370 $this->get_js_assets_url( 'waypoints', 'assets/lib/waypoints/' ),
371 [
372 'jquery',
373 ],
374 '4.0.2',
375 true
376 );
377
378 wp_register_script(
379 'flatpickr',
380 $this->get_js_assets_url( 'flatpickr', 'assets/lib/flatpickr/' ),
381 [
382 'jquery',
383 ],
384 '4.1.4',
385 true
386 );
387
388 wp_register_script(
389 'imagesloaded',
390 $this->get_js_assets_url( 'imagesloaded', 'assets/lib/imagesloaded/' ),
391 [
392 'jquery',
393 ],
394 '4.1.0',
395 true
396 );
397
398 wp_register_script(
399 'jquery-numerator',
400 $this->get_js_assets_url( 'jquery-numerator', 'assets/lib/jquery-numerator/' ),
401 [
402 'jquery',
403 ],
404 '0.2.1',
405 true
406 );
407
408 wp_register_script(
409 'elementor-dialog',
410 $this->get_js_assets_url( 'dialog', 'assets/lib/dialog/' ),
411 [
412 'jquery-ui-position',
413 ],
414 '4.9.0',
415 true
416 );
417
418 wp_register_script(
419 'elementor-gallery',
420 $this->get_js_assets_url( 'e-gallery', 'assets/lib/e-gallery/js/' ),
421 [
422 'jquery',
423 ],
424 '1.2.0',
425 true
426 );
427
428 wp_register_script(
429 'share-link',
430 $this->get_js_assets_url( 'share-link', 'assets/lib/share-link/' ),
431 [
432 'jquery',
433 ],
434 ELEMENTOR_VERSION,
435 true
436 );
437
438 wp_register_script(
439 'elementor-frontend',
440 $this->get_js_assets_url( 'frontend' ),
441 $this->get_elementor_frontend_dependencies(),
442 ELEMENTOR_VERSION,
443 true
444 );
445
446 /**
447 * After frontend register scripts.
448 *
449 * Fires after Elementor frontend scripts are registered.
450 *
451 * @since 1.2.1
452 */
453 do_action( 'elementor/frontend/after_register_scripts' );
454 }
455
456 /**
457 * Registers styles.
458 *
459 * Registers all the frontend styles.
460 *
461 * Fired by `wp_enqueue_scripts` action.
462 *
463 * @since 1.2.0
464 * @access public
465 */
466 public function register_styles() {
467 /**
468 * Before frontend register styles.
469 *
470 * Fires before Elementor frontend styles are registered.
471 *
472 * @since 1.2.0
473 */
474 do_action( 'elementor/frontend/before_register_styles' );
475
476 wp_register_style(
477 'font-awesome',
478 $this->get_css_assets_url( 'font-awesome', 'assets/lib/font-awesome/css/' ),
479 [],
480 '4.7.0'
481 );
482
483 wp_register_style(
484 'elementor-icons',
485 $this->get_css_assets_url( 'elementor-icons', 'assets/lib/eicons/css/' ),
486 [],
487 '5.13.0'
488 );
489
490 wp_register_style(
491 'flatpickr',
492 $this->get_css_assets_url( 'flatpickr', 'assets/lib/flatpickr/' ),
493 [],
494 '4.1.4'
495 );
496
497 wp_register_style(
498 'elementor-gallery',
499 $this->get_css_assets_url( 'e-gallery', 'assets/lib/e-gallery/css/' ),
500 [],
501 '1.2.0'
502 );
503
504 $min_suffix = Utils::is_script_debug() ? '' : '.min';
505
506 $direction_suffix = is_rtl() ? '-rtl' : '';
507
508 $frontend_base_file_name = $this->is_optimized_css_mode() ? 'frontend-lite' : 'frontend';
509
510 $frontend_file_name = $frontend_base_file_name . $direction_suffix . $min_suffix . '.css';
511
512 $frontend_dependencies = [];
513
514 $has_custom_breakpoints = Plugin::$instance->breakpoints->has_custom_breakpoints();
515
516 if ( ! Plugin::$instance->experiments->is_feature_active( 'e_dom_optimization' ) ) {
517 // If The Dom Optimization feature is disabled, register the legacy CSS
518 wp_register_style(
519 'elementor-frontend-legacy',
520 $this->get_frontend_file_url( 'frontend-legacy' . $direction_suffix . $min_suffix . '.css', $has_custom_breakpoints ),
521 [],
522 ELEMENTOR_VERSION
523 );
524
525 $frontend_dependencies[] = 'elementor-frontend-legacy';
526 }
527
528 wp_register_style(
529 'elementor-frontend',
530 $this->get_frontend_file_url( $frontend_file_name, $has_custom_breakpoints ),
531 $frontend_dependencies,
532 $has_custom_breakpoints ? null : ELEMENTOR_VERSION
533 );
534
535 /**
536 * After frontend register styles.
537 *
538 * Fires after Elementor frontend styles are registered.
539 *
540 * @since 1.2.0
541 */
542 do_action( 'elementor/frontend/after_register_styles' );
543 }
544
545 /**
546 * Enqueue scripts.
547 *
548 * Enqueue all the frontend scripts.
549 *
550 * @since 1.0.0
551 * @access public
552 */
553 public function enqueue_scripts() {
554 /**
555 * Before frontend enqueue scripts.
556 *
557 * Fires before Elementor frontend scripts are enqueued.
558 *
559 * @since 1.0.0
560 */
561 do_action( 'elementor/frontend/before_enqueue_scripts' );
562
563 wp_enqueue_script( 'elementor-frontend' );
564
565 if ( ! $this->is_improved_assets_loading() ) {
566 wp_enqueue_script(
567 'preloaded-modules',
568 $this->get_js_assets_url( 'preloaded-modules', 'assets/js/' ),
569 [
570 'elementor-frontend',
571 ],
572 ELEMENTOR_VERSION,
573 true
574 );
575 }
576
577 $this->print_config();
578
579 $this->enqueue_conditional_assets();
580
581 /**
582 * After frontend enqueue scripts.
583 *
584 * Fires after Elementor frontend scripts are enqueued.
585 *
586 * @since 1.0.0
587 */
588 do_action( 'elementor/frontend/after_enqueue_scripts' );
589 }
590
591 /**
592 * Enqueue styles.
593 *
594 * Enqueue all the frontend styles.
595 *
596 * Fired by `wp_enqueue_scripts` action.
597 *
598 * @since 1.0.0
599 * @access public
600 */
601 public function enqueue_styles() {
602 static $is_enqueue_styles_already_triggered;
603
604 if ( ! $is_enqueue_styles_already_triggered ) {
605 $is_enqueue_styles_already_triggered = true;
606
607 /**
608 * Before frontend styles enqueued.
609 *
610 * Fires before Elementor frontend styles are enqueued.
611 *
612 * @since 1.0.0
613 */
614 do_action( 'elementor/frontend/before_enqueue_styles' );
615
616 // The e-icons are needed in preview mode for the editor icons (plus-icon for new section, folder-icon for the templates library etc.).
617 if ( ! Plugin::$instance->experiments->is_feature_active( 'e_font_icon_svg' ) || Plugin::$instance->preview->is_preview_mode() ) {
618 wp_enqueue_style( 'elementor-icons' );
619 }
620
621 wp_enqueue_style( 'elementor-frontend' );
622
623 /**
624 * After frontend styles enqueued.
625 *
626 * Fires after Elementor frontend styles are enqueued.
627 *
628 * @since 1.0.0
629 */
630 do_action( 'elementor/frontend/after_enqueue_styles' );
631
632 if ( ! Plugin::$instance->preview->is_preview_mode() ) {
633 $this->parse_global_css_code();
634
635 $post_id = get_the_ID();
636 // Check $post_id for virtual pages. check is singular because the $post_id is set to the first post on archive pages.
637 if ( $post_id && is_singular() ) {
638 $css_file = Post_CSS::create( get_the_ID() );
639 $css_file->enqueue();
640 }
641 }
642 }
643 }
644
645 /**
646 * Get Frontend File URL
647 *
648 * Returns the URL for the CSS file to be loaded in the front end. If requested via the second parameter, a custom
649 * file is generated based on a passed template file name. Otherwise, the URL for the default CSS file is returned.
650 *
651 * @since 3.4.5
652 *
653 * @access public
654 *
655 * @param string $frontend_file_name
656 * @param boolean $custom_file
657 *
658 * @return string frontend file URL
659 */
660 public function get_frontend_file_url( $frontend_file_name, $custom_file ) {
661 if ( $custom_file ) {
662 $frontend_file = $this->get_frontend_file( $frontend_file_name );
663
664 $frontend_file_url = $frontend_file->get_url();
665 } else {
666 $frontend_file_url = ELEMENTOR_ASSETS_URL . 'css/' . $frontend_file_name;
667 }
668
669 return $frontend_file_url;
670 }
671
672 /**
673 * Get Frontend File Path
674 *
675 * Returns the path for the CSS file to be loaded in the front end. If requested via the second parameter, a custom
676 * file is generated based on a passed template file name. Otherwise, the path for the default CSS file is returned.
677 *
678 * @since 3.5.0
679 * @access public
680 *
681 * @param string $frontend_file_name
682 * @param boolean $custom_file
683 *
684 * @return string frontend file path
685 */
686 public function get_frontend_file_path( $frontend_file_name, $custom_file ) {
687 if ( $custom_file ) {
688 $frontend_file = $this->get_frontend_file( $frontend_file_name );
689
690 $frontend_file_path = $frontend_file->get_path();
691 } else {
692 $frontend_file_path = ELEMENTOR_ASSETS_PATH . 'css/' . $frontend_file_name;
693 }
694
695 return $frontend_file_path;
696 }
697
698 /**
699 * Get Frontend File
700 *
701 * Returns a frontend file instance.
702 *
703 * @since 3.5.0
704 * @access public
705 *
706 * @param string $frontend_file_name
707 * @param string $file_prefix
708 * @param string $template_file_path
709 *
710 * @return FrontendFile
711 */
712 public function get_frontend_file( $frontend_file_name, $file_prefix = 'custom-', $template_file_path = '' ) {
713 static $cached_frontend_files = [];
714
715 $file_name = $file_prefix . $frontend_file_name;
716
717 if ( isset( $cached_frontend_files[ $file_name ] ) ) {
718 return $cached_frontend_files[ $file_name ];
719 }
720
721 if ( ! $template_file_path ) {
722 $template_file_path = Breakpoints_Manager::get_stylesheet_templates_path() . $frontend_file_name;
723 }
724
725 $frontend_file = new FrontendFile( $file_name, $template_file_path );
726
727 $time = $frontend_file->get_meta( 'time' );
728
729 if ( ! $time ) {
730 $frontend_file->update();
731 }
732
733 $cached_frontend_files[ $file_name ] = $frontend_file;
734
735 return $frontend_file;
736 }
737
738 /**
739 * Enqueue assets conditionally.
740 *
741 * Enqueue all assets that were pre-enabled.
742 *
743 * @since 3.3.0
744 * @access private
745 */
746 private function enqueue_conditional_assets() {
747 Plugin::$instance->assets_loader->enqueue_assets();
748 }
749
750 /**
751 * Elementor footer scripts and styles.
752 *
753 * Handle styles and scripts that are not printed in the header.
754 *
755 * Fired by `wp_footer` action.
756 *
757 * @since 1.0.11
758 * @access public
759 */
760 public function wp_footer() {
761 if ( ! $this->_has_elementor_in_page ) {
762 return;
763 }
764
765 $this->enqueue_styles();
766 $this->enqueue_scripts();
767
768 $this->print_fonts_links();
769 }
770
771 /**
772 * Print fonts links.
773 *
774 * Enqueue all the frontend fonts by url.
775 *
776 * Fired by `wp_head` action.
777 *
778 * @since 1.9.4
779 * @access public
780 */
781 public function print_fonts_links() {
782 $google_fonts = [
783 'google' => [],
784 'early' => [],
785 ];
786
787 foreach ( $this->fonts_to_enqueue as $key => $font ) {
788 $font_type = Fonts::get_font_type( $font );
789
790 switch ( $font_type ) {
791 case Fonts::GOOGLE:
792 $google_fonts['google'][] = $font;
793 break;
794
795 case Fonts::EARLYACCESS:
796 $google_fonts['early'][] = $font;
797 break;
798
799 case false:
800 $this->maybe_enqueue_icon_font( $font );
801 break;
802 default:
803 /**
804 * Print font links.
805 *
806 * Fires when Elementor frontend fonts are printed on the HEAD tag.
807 *
808 * The dynamic portion of the hook name, `$font_type`, refers to the font type.
809 *
810 * @since 2.0.0
811 *
812 * @param string $font Font name.
813 */
814 do_action( "elementor/fonts/print_font_links/{$font_type}", $font );
815 }
816 }
817 $this->fonts_to_enqueue = [];
818
819 $this->enqueue_google_fonts( $google_fonts );
820 $this->enqueue_icon_fonts();
821 }
822
823 private function maybe_enqueue_icon_font( $icon_font_type ) {
824 if ( ! Icons_Manager::is_migration_allowed() ) {
825 return;
826 }
827
828 $icons_types = Icons_Manager::get_icon_manager_tabs();
829 if ( ! isset( $icons_types[ $icon_font_type ] ) ) {
830 return;
831 }
832
833 $icon_type = $icons_types[ $icon_font_type ];
834 if ( isset( $icon_type['url'] ) ) {
835 $this->icon_fonts_to_enqueue[ $icon_font_type ] = [ $icon_type['url'] ];
836 }
837 }
838
839 private function enqueue_icon_fonts() {
840 if ( empty( $this->icon_fonts_to_enqueue ) || ! Icons_Manager::is_migration_allowed() ) {
841 return;
842 }
843
844 foreach ( $this->icon_fonts_to_enqueue as $icon_type => $css_url ) {
845 wp_enqueue_style( 'elementor-icons-' . $icon_type );
846 $this->enqueued_icon_fonts[] = $css_url;
847 }
848
849 //clear enqueued icons
850 $this->icon_fonts_to_enqueue = [];
851 }
852
853 /**
854 * Print Google fonts.
855 *
856 * Enqueue all the frontend Google fonts.
857 *
858 * Fired by `wp_head` action.
859 *
860 * @since 1.0.0
861 * @access private
862 *
863 * @param array $google_fonts Optional. Google fonts to print in the frontend.
864 * Default is an empty array.
865 */
866 private function enqueue_google_fonts( $google_fonts = [] ) {
867 static $google_fonts_index = 0;
868
869 $print_google_fonts = true;
870
871 /**
872 * Print frontend google fonts.
873 *
874 * Filters whether to enqueue Google fonts in the frontend.
875 *
876 * @since 1.0.0
877 *
878 * @param bool $print_google_fonts Whether to enqueue Google fonts. Default is true.
879 */
880 $print_google_fonts = apply_filters( 'elementor/frontend/print_google_fonts', $print_google_fonts );
881
882 if ( ! $print_google_fonts ) {
883 return;
884 }
885
886 // Print used fonts
887 if ( ! empty( $google_fonts['google'] ) ) {
888 $google_fonts_index++;
889
890 foreach ( $google_fonts['google'] as &$font ) {
891 $font = str_replace( ' ', '+', $font ) . ':100,100italic,200,200italic,300,300italic,400,400italic,500,500italic,600,600italic,700,700italic,800,800italic,900,900italic';
892 }
893
894 // Defining a font-display type to google fonts.
895 $font_display_url_str = '&display=' . Fonts::get_font_display_setting();
896
897 $fonts_url = sprintf( 'https://fonts.googleapis.com/css?family=%1$s%2$s', implode( rawurlencode( '|' ), $google_fonts['google'] ), $font_display_url_str );
898
899 $subsets = [
900 'ru_RU' => 'cyrillic',
901 'bg_BG' => 'cyrillic',
902 'he_IL' => 'hebrew',
903 'el' => 'greek',
904 'vi' => 'vietnamese',
905 'uk' => 'cyrillic',
906 'cs_CZ' => 'latin-ext',
907 'ro_RO' => 'latin-ext',
908 'pl_PL' => 'latin-ext',
909 'hr_HR' => 'latin-ext',
910 'hu_HU' => 'latin-ext',
911 'sk_SK' => 'latin-ext',
912 'tr_TR' => 'latin-ext',
913 'lt_LT' => 'latin-ext',
914 ];
915
916 /**
917 * Google font subsets.
918 *
919 * Filters the list of Google font subsets from which locale will be enqueued in frontend.
920 *
921 * @since 1.0.0
922 *
923 * @param array $subsets A list of font subsets.
924 */
925 $subsets = apply_filters( 'elementor/frontend/google_font_subsets', $subsets );
926
927 $locale = get_locale();
928
929 if ( isset( $subsets[ $locale ] ) ) {
930 $fonts_url .= '&subset=' . $subsets[ $locale ];
931 }
932
933 wp_enqueue_style( 'google-fonts-' . $google_fonts_index, $fonts_url ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
934 }
935
936 if ( ! empty( $google_fonts['early'] ) ) {
937 foreach ( $google_fonts['early'] as $current_font ) {
938 $google_fonts_index++;
939
940 //printf( '<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/earlyaccess/%s.css">', strtolower( str_replace( ' ', '', $current_font ) ) );
941
942 $font_url = sprintf( 'https://fonts.googleapis.com/earlyaccess/%s.css', strtolower( str_replace( ' ', '', $current_font ) ) );
943
944 wp_enqueue_style( 'google-earlyaccess-' . $google_fonts_index, $font_url ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
945 }
946 }
947
948 }
949
950 /**
951 * Enqueue fonts.
952 *
953 * Enqueue all the frontend fonts.
954 *
955 * @since 1.2.0
956 * @access public
957 *
958 * @param array $font Fonts to enqueue in the frontend.
959 */
960 public function enqueue_font( $font ) {
961 if ( in_array( $font, $this->registered_fonts ) ) {
962 return;
963 }
964
965 $this->fonts_to_enqueue[] = $font;
966 $this->registered_fonts[] = $font;
967 }
968
969 /**
970 * Parse global CSS.
971 *
972 * Enqueue the global CSS file.
973 *
974 * @since 1.2.0
975 * @access protected
976 */
977 protected function parse_global_css_code() {
978 $scheme_css_file = Global_CSS::create( 'global.css' );
979
980 $scheme_css_file->enqueue();
981 }
982
983 /**
984 * Apply builder in content.
985 *
986 * Used to apply the Elementor page editor on the post content.
987 *
988 * @since 1.0.0
989 * @access public
990 *
991 * @param string $content The post content.
992 *
993 * @return string The post content.
994 */
995 public function apply_builder_in_content( $content ) {
996 $this->restore_content_filters();
997
998 if ( Plugin::$instance->preview->is_preview_mode() || $this->_is_excerpt ) {
999 return $content;
1000 }
1001
1002 // Remove the filter itself in order to allow other `the_content` in the elements
1003 $this->remove_content_filter();
1004
1005 $post_id = get_the_ID();
1006 $builder_content = $this->get_builder_content( $post_id );
1007
1008 if ( ! empty( $builder_content ) ) {
1009 $content = $builder_content;
1010 $this->remove_content_filters();
1011 }
1012
1013 // Add the filter again for other `the_content` calls
1014 $this->add_content_filter();
1015
1016 return $content;
1017 }
1018
1019 /**
1020 * Retrieve builder content.
1021 *
1022 * Used to render and return the post content with all the Elementor elements.
1023 *
1024 * Note that this method is an internal method, please use `get_builder_content_for_display()`.
1025 *
1026 * @since 1.0.0
1027 * @access public
1028 *
1029 * @param int $post_id The post ID.
1030 * @param bool $with_css Optional. Whether to retrieve the content with CSS
1031 * or not. Default is false.
1032 *
1033 * @return string The post content.
1034 */
1035 public function get_builder_content( $post_id, $with_css = false ) {
1036 if ( post_password_required( $post_id ) ) {
1037 return '';
1038 }
1039
1040 $document = Plugin::$instance->documents->get_doc_for_frontend( $post_id );
1041
1042 if ( ! $document || ! $document->is_built_with_elementor() ) {
1043 return '';
1044 }
1045
1046 // Change the current post, so widgets can use `documents->get_current`.
1047 Plugin::$instance->documents->switch_to_document( $document );
1048
1049 $data = $document->get_elements_data();
1050
1051 /**
1052 * Frontend builder content data.
1053 *
1054 * Filters the builder content in the frontend.
1055 *
1056 * @since 1.0.0
1057 *
1058 * @param array $data The builder content.
1059 * @param int $post_id The post ID.
1060 */
1061 $data = apply_filters( 'elementor/frontend/builder_content_data', $data, $post_id );
1062
1063 do_action( 'elementor/frontend/before_get_builder_content', $document, $this->_is_excerpt );
1064
1065 if ( empty( $data ) ) {
1066 Plugin::$instance->documents->restore_document();
1067
1068 return '';
1069 }
1070
1071 if ( ! $this->_is_excerpt ) {
1072 if ( $document->is_autosave() ) {
1073 $css_file = Post_Preview::create( $document->get_post()->ID );
1074 } else {
1075 $css_file = Post_CSS::create( $post_id );
1076 }
1077
1078 $css_file->enqueue();
1079 }
1080
1081 ob_start();
1082
1083 // Handle JS and Customizer requests, with CSS inline.
1084 if ( is_customize_preview() || wp_doing_ajax() ) {
1085 $with_css = true;
1086 }
1087
1088 if ( ! empty( $css_file ) && $with_css ) {
1089 $css_file->print_css();
1090 }
1091
1092 $document->print_elements_with_wrapper( $data );
1093
1094 $content = ob_get_clean();
1095
1096 $content = $this->process_more_tag( $content );
1097
1098 /**
1099 * Frontend content.
1100 *
1101 * Filters the content in the frontend.
1102 *
1103 * @since 1.0.0
1104 *
1105 * @param string $content The content.
1106 */
1107 $content = apply_filters( 'elementor/frontend/the_content', $content );
1108
1109 if ( ! empty( $content ) ) {
1110 $this->_has_elementor_in_page = true;
1111 }
1112
1113 Plugin::$instance->documents->restore_document();
1114
1115 // BC
1116 // TODO: use Deprecation::do_deprecated_action() in 3.1.0
1117 do_action( 'elementor/frontend/get_builder_content', $document, $this->_is_excerpt, $with_css );
1118
1119 return $content;
1120 }
1121
1122 /**
1123 * Retrieve builder content for display.
1124 *
1125 * Used to render and return the post content with all the Elementor elements.
1126 *
1127 * @since 1.0.0
1128 * @access public
1129 *
1130 * @param int $post_id The post ID.
1131 *
1132 * @param bool $with_css Optional. Whether to retrieve the content with CSS
1133 * or not. Default is false.
1134 *
1135 * @return string The post content.
1136 */
1137 public function get_builder_content_for_display( $post_id, $with_css = false ) {
1138 if ( ! get_post( $post_id ) ) {
1139 return '';
1140 }
1141
1142 $editor = Plugin::$instance->editor;
1143
1144 // Avoid recursion
1145 if ( get_the_ID() === (int) $post_id ) {
1146 $content = '';
1147 if ( $editor->is_edit_mode() ) {
1148 $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>';
1149 }
1150
1151 return $content;
1152 }
1153
1154 // 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
1155 $is_edit_mode = $editor->is_edit_mode();
1156 $editor->set_edit_mode( false );
1157
1158 $with_css = $with_css ? true : $is_edit_mode;
1159
1160 $content = $this->get_builder_content( $post_id, $with_css );
1161
1162 // Restore edit mode state
1163 Plugin::$instance->editor->set_edit_mode( $is_edit_mode );
1164
1165 return $content;
1166 }
1167
1168 /**
1169 * Start excerpt flag.
1170 *
1171 * Flags when `the_excerpt` is called. Used to avoid enqueueing CSS in the excerpt.
1172 *
1173 * @since 1.4.3
1174 * @access public
1175 *
1176 * @param string $excerpt The post excerpt.
1177 *
1178 * @return string The post excerpt.
1179 */
1180 public function start_excerpt_flag( $excerpt ) {
1181 $this->_is_excerpt = true;
1182 return $excerpt;
1183 }
1184
1185 /**
1186 * End excerpt flag.
1187 *
1188 * Flags when `the_excerpt` call ended.
1189 *
1190 * @since 1.4.3
1191 * @access public
1192 *
1193 * @param string $excerpt The post excerpt.
1194 *
1195 * @return string The post excerpt.
1196 */
1197 public function end_excerpt_flag( $excerpt ) {
1198 $this->_is_excerpt = false;
1199 return $excerpt;
1200 }
1201
1202 /**
1203 * Remove content filters.
1204 *
1205 * Remove WordPress default filters that conflicted with Elementor.
1206 *
1207 * @since 1.5.0
1208 * @access public
1209 */
1210 public function remove_content_filters() {
1211 $filters = [
1212 'wpautop',
1213 'shortcode_unautop',
1214 'wptexturize',
1215 ];
1216
1217 foreach ( $filters as $filter ) {
1218 // Check if another plugin/theme do not already removed the filter.
1219 if ( has_filter( 'the_content', $filter ) ) {
1220 remove_filter( 'the_content', $filter );
1221 $this->content_removed_filters[] = $filter;
1222 }
1223 }
1224 }
1225
1226 /**
1227 * Has Elementor In Page
1228 *
1229 * Determine whether the current page is using Elementor.
1230 *
1231 * @since 2.0.9
1232 *
1233 * @access public
1234 * @return bool
1235 */
1236 public function has_elementor_in_page() {
1237 return $this->_has_elementor_in_page;
1238 }
1239
1240 public function create_action_hash( $action, array $settings = [] ) {
1241 return '#' . rawurlencode( sprintf( 'elementor-action:action=%1$s&settings=%2$s', $action, base64_encode( wp_json_encode( $settings ) ) ) );
1242 }
1243
1244 /**
1245 * Is the current render mode is static.
1246 *
1247 * @return bool
1248 */
1249 public function is_static_render_mode() {
1250 // The render mode manager is exists only in frontend,
1251 // so by default if it is not exist the method will return false.
1252 if ( ! $this->render_mode_manager ) {
1253 return false;
1254 }
1255
1256 return $this->render_mode_manager->get_current()->is_static();
1257 }
1258
1259 /**
1260 * Get Init Settings
1261 *
1262 * Used to define the default/initial settings of the object. Inheriting classes may implement this method to define
1263 * their own default/initial settings.
1264 *
1265 * @since 2.3.0
1266 *
1267 * @access protected
1268 * @return array
1269 */
1270 protected function get_init_settings() {
1271 $is_preview_mode = Plugin::$instance->preview->is_preview_mode( Plugin::$instance->preview->get_post_id() );
1272
1273 $active_experimental_features = Plugin::$instance->experiments->get_active_features();
1274
1275 $active_experimental_features = array_fill_keys( array_keys( $active_experimental_features ), true );
1276
1277 $assets_url = ELEMENTOR_ASSETS_URL;
1278
1279 /**
1280 * Frontend assets URL
1281 *
1282 * Filters Elementor frontend assets URL.
1283 *
1284 * @since 2.3.0
1285 *
1286 * @param string $assets_url The frontend assets URL. Default is ELEMENTOR_ASSETS_URL.
1287 */
1288 $assets_url = apply_filters( 'elementor/frontend/assets_url', $assets_url );
1289
1290 $settings = [
1291 'environmentMode' => [
1292 'edit' => $is_preview_mode,
1293 'wpPreview' => is_preview(),
1294 'isScriptDebug' => Utils::is_script_debug(),
1295 ],
1296 'i18n' => [
1297 'shareOnFacebook' => esc_html__( 'Share on Facebook', 'elementor' ),
1298 'shareOnTwitter' => esc_html__( 'Share on Twitter', 'elementor' ),
1299 'pinIt' => esc_html__( 'Pin it', 'elementor' ),
1300 'download' => esc_html__( 'Download', 'elementor' ),
1301 'downloadImage' => esc_html__( 'Download image', 'elementor' ),
1302 'fullscreen' => esc_html__( 'Fullscreen', 'elementor' ),
1303 'zoom' => esc_html__( 'Zoom', 'elementor' ),
1304 'share' => esc_html__( 'Share', 'elementor' ),
1305 'playVideo' => esc_html__( 'Play Video', 'elementor' ),
1306 'previous' => esc_html__( 'Previous', 'elementor' ),
1307 'next' => esc_html__( 'Next', 'elementor' ),
1308 'close' => esc_html__( 'Close', 'elementor' ),
1309 ],
1310 'is_rtl' => is_rtl(),
1311 // 'breakpoints' object is kept for BC.
1312 'breakpoints' => Responsive::get_breakpoints(),
1313 // 'responsive' contains the custom breakpoints config introduced in Elementor v3.2.0
1314 'responsive' => [
1315 'breakpoints' => Plugin::$instance->breakpoints->get_breakpoints_config(),
1316 ],
1317 'version' => ELEMENTOR_VERSION,
1318 'is_static' => $this->is_static_render_mode(),
1319 'experimentalFeatures' => $active_experimental_features,
1320 'urls' => [
1321 'assets' => $assets_url,
1322 ],
1323 ];
1324
1325 $settings['settings'] = SettingsManager::get_settings_frontend_config();
1326
1327 $kit = Plugin::$instance->kits_manager->get_active_kit_for_frontend();
1328 $settings['kit'] = $kit->get_frontend_settings();
1329
1330 if ( is_singular() ) {
1331 $post = get_post();
1332
1333 $title = Utils::urlencode_html_entities( wp_get_document_title() );
1334
1335 // Try to use the 'large' WP image size because the Pinterest share API
1336 // has problems accepting shares with large images sometimes, and the WP 'large' thumbnail is
1337 // the largest default WP image size that will probably not be changed in most sites
1338 $featured_image_url = get_the_post_thumbnail_url( null, 'large' );
1339
1340 // If the large size was nullified, use the full size which cannot be nullified/deleted
1341 if ( ! $featured_image_url ) {
1342 $featured_image_url = get_the_post_thumbnail_url( null, 'full' );
1343 }
1344
1345 $settings['post'] = [
1346 'id' => $post->ID,
1347 'title' => $title,
1348 'excerpt' => $post->post_excerpt,
1349 'featuredImage' => $featured_image_url,
1350 ];
1351 } else {
1352 $settings['post'] = [
1353 'id' => 0,
1354 'title' => wp_get_document_title(),
1355 'excerpt' => get_the_archive_description(),
1356 ];
1357 }
1358
1359 $empty_object = (object) [];
1360
1361 if ( $is_preview_mode ) {
1362 $settings['elements'] = [
1363 'data' => $empty_object,
1364 'editSettings' => $empty_object,
1365 'keys' => $empty_object,
1366 ];
1367 }
1368
1369 if ( is_user_logged_in() ) {
1370 $user = wp_get_current_user();
1371
1372 if ( ! empty( $user->roles ) ) {
1373 $settings['user'] = [
1374 'roles' => $user->roles,
1375 ];
1376 }
1377 }
1378
1379 return $settings;
1380 }
1381
1382 /**
1383 * Restore content filters.
1384 *
1385 * Restore removed WordPress filters that conflicted with Elementor.
1386 *
1387 * @since 1.5.0
1388 * @access public
1389 */
1390 public function restore_content_filters() {
1391 foreach ( $this->content_removed_filters as $filter ) {
1392 add_filter( 'the_content', $filter );
1393 }
1394
1395 $this->content_removed_filters = [];
1396 }
1397
1398 /**
1399 * Process More Tag
1400 *
1401 * Respect the native WP (<!--more-->) tag
1402 *
1403 * @access private
1404 * @since 2.0.4
1405 *
1406 * @param $content
1407 *
1408 * @return string
1409 */
1410 private function process_more_tag( $content ) {
1411 $post = get_post();
1412 $content = str_replace( '&lt;!--more--&gt;', '<!--more-->', $content );
1413 $parts = get_extended( $content );
1414 if ( empty( $parts['extended'] ) ) {
1415 return $content;
1416 }
1417
1418 if ( is_singular() ) {
1419 return $parts['main'] . '<div id="more-' . $post->ID . '"></div>' . $parts['extended'];
1420 }
1421
1422 if ( empty( $parts['more_text'] ) ) {
1423 $parts['more_text'] = esc_html__( '(more&hellip;)', 'elementor' );
1424 }
1425
1426 $more_link_text = sprintf(
1427 '<span aria-label="%1$s">%2$s</span>',
1428 sprintf(
1429 /* translators: %s: Current post name. */
1430 __( 'Continue reading %s', 'elementor' ),
1431 the_title_attribute( [
1432 'echo' => false,
1433 ] )
1434 ),
1435 $parts['more_text']
1436 );
1437
1438 $more_link = sprintf( ' <a href="%s#more-%s" class="more-link elementor-more-link">%s</a>', get_permalink(), $post->ID, $more_link_text );
1439
1440 /**
1441 * The content "more" link.
1442 *
1443 * Filters the "more" link displayed after the content.
1444 *
1445 * This hook can be used either to change the link syntax or to change the
1446 * text inside the link.
1447 *
1448 * @since 2.0.4
1449 *
1450 * @param string $more_link The more link.
1451 * @param string $more_link_text The text inside the more link.
1452 */
1453 $more_link = apply_filters( 'the_content_more_link', $more_link, $more_link_text );
1454
1455 return force_balance_tags( $parts['main'] ) . $more_link;
1456 }
1457
1458 private function is_improved_assets_loading() {
1459 return Plugin::$instance->experiments->is_feature_active( 'e_optimized_assets_loading' );
1460 }
1461
1462 private function get_elementor_frontend_dependencies() {
1463 $dependencies = [
1464 'elementor-frontend-modules',
1465 'elementor-waypoints',
1466 'jquery-ui-position',
1467 ];
1468
1469 if ( ! $this->is_improved_assets_loading() ) {
1470 wp_register_script(
1471 'swiper',
1472 $this->get_js_assets_url( 'swiper', 'assets/lib/swiper/' ),
1473 [],
1474 '5.3.6',
1475 true
1476 );
1477
1478 $dependencies[] = 'swiper';
1479 $dependencies[] = 'share-link';
1480 $dependencies[] = 'elementor-dialog';
1481 }
1482
1483 return $dependencies;
1484 }
1485
1486 private function is_optimized_css_mode() {
1487 $is_optimized_css_loading = Plugin::$instance->experiments->is_feature_active( 'e_optimized_css_loading' );
1488
1489 return ! Utils::is_script_debug() && $is_optimized_css_loading && ! Plugin::$instance->preview->is_preview_mode();
1490 }
1491 }
1492