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