| 1 |
<?php |
| 2 |
namespace Elementor; |
| 3 |
|
| 4 |
if ( ! defined( 'ABSPATH' ) ) { |
| 5 |
exit; // Exit if accessed directly. |
| 6 |
} |
| 7 |
|
| 8 |
/** |
| 9 |
* Elementor element base. |
| 10 |
* |
| 11 |
* An abstract class to register new Elementor elements. It extended the |
| 12 |
* `Controls_Stack` class to inherit its properties. |
| 13 |
* |
| 14 |
* This abstract class must be extended in order to register new elements. |
| 15 |
* |
| 16 |
* @since 1.0.0 |
| 17 |
* @abstract |
| 18 |
*/ |
| 19 |
abstract class Element_Base extends Controls_Stack { |
| 20 |
|
| 21 |
/** |
| 22 |
* Child elements. |
| 23 |
* |
| 24 |
* Holds all the child elements of the element. |
| 25 |
* |
| 26 |
* @access private |
| 27 |
* |
| 28 |
* @var Element_Base[] |
| 29 |
*/ |
| 30 |
private $children; |
| 31 |
|
| 32 |
/** |
| 33 |
* Element render attributes. |
| 34 |
* |
| 35 |
* Holds all the render attributes of the element. Used to store data like |
| 36 |
* the HTML class name and the class value, or HTML element ID name and value. |
| 37 |
* |
| 38 |
* @access private |
| 39 |
* |
| 40 |
* @var array |
| 41 |
*/ |
| 42 |
private $render_attributes = []; |
| 43 |
|
| 44 |
/** |
| 45 |
* Element default arguments. |
| 46 |
* |
| 47 |
* Holds all the default arguments of the element. Used to store additional |
| 48 |
* data. For example WordPress widgets use this to store widget names. |
| 49 |
* |
| 50 |
* @access private |
| 51 |
* |
| 52 |
* @var array |
| 53 |
*/ |
| 54 |
private $default_args = []; |
| 55 |
|
| 56 |
/** |
| 57 |
* Is type instance. |
| 58 |
* |
| 59 |
* Whether the element is an instance of that type or not. |
| 60 |
* |
| 61 |
* @access private |
| 62 |
* |
| 63 |
* @var bool |
| 64 |
*/ |
| 65 |
private $is_type_instance = true; |
| 66 |
|
| 67 |
/** |
| 68 |
* Depended scripts. |
| 69 |
* |
| 70 |
* Holds all the element depended scripts to enqueue. |
| 71 |
* |
| 72 |
* @since 1.9.0 |
| 73 |
* @access private |
| 74 |
* |
| 75 |
* @var array |
| 76 |
*/ |
| 77 |
private $depended_scripts = []; |
| 78 |
|
| 79 |
/** |
| 80 |
* Depended styles. |
| 81 |
* |
| 82 |
* Holds all the element depended styles to enqueue. |
| 83 |
* |
| 84 |
* @since 1.9.0 |
| 85 |
* @access private |
| 86 |
* |
| 87 |
* @var array |
| 88 |
*/ |
| 89 |
private $depended_styles = []; |
| 90 |
|
| 91 |
/** |
| 92 |
* Add script depends. |
| 93 |
* |
| 94 |
* Register new script to enqueue by the handler. |
| 95 |
* |
| 96 |
* @since 1.9.0 |
| 97 |
* @access public |
| 98 |
* |
| 99 |
* @param string $handler Depend script handler. |
| 100 |
*/ |
| 101 |
public function add_script_depends( $handler ) { |
| 102 |
$this->depended_scripts[] = $handler; |
| 103 |
} |
| 104 |
|
| 105 |
/** |
| 106 |
* Add style depends. |
| 107 |
* |
| 108 |
* Register new style to enqueue by the handler. |
| 109 |
* |
| 110 |
* @since 1.9.0 |
| 111 |
* @access public |
| 112 |
* |
| 113 |
* @param string $handler Depend style handler. |
| 114 |
*/ |
| 115 |
public function add_style_depends( $handler ) { |
| 116 |
$this->depended_styles[] = $handler; |
| 117 |
} |
| 118 |
|
| 119 |
/** |
| 120 |
* Get script dependencies. |
| 121 |
* |
| 122 |
* Retrieve the list of script dependencies the element requires. |
| 123 |
* |
| 124 |
* @since 1.3.0 |
| 125 |
* @access public |
| 126 |
* |
| 127 |
* @return array Element scripts dependencies. |
| 128 |
*/ |
| 129 |
public function get_script_depends() { |
| 130 |
return $this->depended_scripts; |
| 131 |
} |
| 132 |
|
| 133 |
/** |
| 134 |
* Enqueue scripts. |
| 135 |
* |
| 136 |
* Registers all the scripts defined as element dependencies and enqueues |
| 137 |
* them. Use `get_script_depends()` method to add custom script dependencies. |
| 138 |
* |
| 139 |
* @since 1.3.0 |
| 140 |
* @access public |
| 141 |
*/ |
| 142 |
final public function enqueue_scripts() { |
| 143 |
$deprecated_scripts = [ |
| 144 |
'jquery-slick' => [ |
| 145 |
'version' => '2.7.0', |
| 146 |
'replacement' => 'Swiper', |
| 147 |
], |
| 148 |
]; |
| 149 |
|
| 150 |
foreach ( $this->get_script_depends() as $script ) { |
| 151 |
if ( isset( $deprecated_scripts[ $script ] ) ) { |
| 152 |
Utils::handle_deprecation( $script, $deprecated_scripts[ $script ]['version'], $deprecated_scripts[ $script ]['replacement'] ); |
| 153 |
} |
| 154 |
|
| 155 |
wp_enqueue_script( $script ); |
| 156 |
} |
| 157 |
} |
| 158 |
|
| 159 |
/** |
| 160 |
* Get style dependencies. |
| 161 |
* |
| 162 |
* Retrieve the list of style dependencies the element requires. |
| 163 |
* |
| 164 |
* @since 1.9.0 |
| 165 |
* @access public |
| 166 |
* |
| 167 |
* @return array Element styles dependencies. |
| 168 |
*/ |
| 169 |
public function get_style_depends() { |
| 170 |
return $this->depended_styles; |
| 171 |
} |
| 172 |
|
| 173 |
/** |
| 174 |
* Enqueue styles. |
| 175 |
* |
| 176 |
* Registers all the styles defined as element dependencies and enqueues |
| 177 |
* them. Use `get_style_depends()` method to add custom style dependencies. |
| 178 |
* |
| 179 |
* @since 1.9.0 |
| 180 |
* @access public |
| 181 |
*/ |
| 182 |
final public function enqueue_styles() { |
| 183 |
foreach ( $this->get_style_depends() as $style ) { |
| 184 |
wp_enqueue_style( $style ); |
| 185 |
} |
| 186 |
} |
| 187 |
|
| 188 |
/** |
| 189 |
* @since 1.0.0 |
| 190 |
* @deprecated 2.6.0 |
| 191 |
* @access public |
| 192 |
* @static |
| 193 |
*/ |
| 194 |
final public static function add_edit_tool() {} |
| 195 |
|
| 196 |
/** |
| 197 |
* @since 2.2.0 |
| 198 |
* @deprecated 2.6.0 |
| 199 |
* @access public |
| 200 |
* @static |
| 201 |
*/ |
| 202 |
final public static function is_edit_buttons_enabled() { |
| 203 |
return get_option( 'elementor_edit_buttons' ); |
| 204 |
} |
| 205 |
|
| 206 |
/** |
| 207 |
* Get default child type. |
| 208 |
* |
| 209 |
* Retrieve the default child type based on element data. |
| 210 |
* |
| 211 |
* Note that not all elements support children. |
| 212 |
* |
| 213 |
* @since 1.0.0 |
| 214 |
* @access protected |
| 215 |
* @abstract |
| 216 |
* |
| 217 |
* @param array $element_data Element data. |
| 218 |
* |
| 219 |
* @return Element_Base |
| 220 |
*/ |
| 221 |
abstract protected function _get_default_child_type( array $element_data ); |
| 222 |
|
| 223 |
/** |
| 224 |
* Before element rendering. |
| 225 |
* |
| 226 |
* Used to add stuff before the element. |
| 227 |
* |
| 228 |
* @since 1.0.0 |
| 229 |
* @access public |
| 230 |
*/ |
| 231 |
public function before_render() {} |
| 232 |
|
| 233 |
/** |
| 234 |
* After element rendering. |
| 235 |
* |
| 236 |
* Used to add stuff after the element. |
| 237 |
* |
| 238 |
* @since 1.0.0 |
| 239 |
* @access public |
| 240 |
*/ |
| 241 |
public function after_render() {} |
| 242 |
|
| 243 |
/** |
| 244 |
* Get element title. |
| 245 |
* |
| 246 |
* Retrieve the element title. |
| 247 |
* |
| 248 |
* @since 1.0.0 |
| 249 |
* @access public |
| 250 |
* |
| 251 |
* @return string Element title. |
| 252 |
*/ |
| 253 |
public function get_title() { |
| 254 |
return ''; |
| 255 |
} |
| 256 |
|
| 257 |
/** |
| 258 |
* Get element icon. |
| 259 |
* |
| 260 |
* Retrieve the element icon. |
| 261 |
* |
| 262 |
* @since 1.0.0 |
| 263 |
* @access public |
| 264 |
* |
| 265 |
* @return string Element icon. |
| 266 |
*/ |
| 267 |
public function get_icon() { |
| 268 |
return 'eicon-columns'; |
| 269 |
} |
| 270 |
|
| 271 |
public function get_help_url() { |
| 272 |
return 'https://go.elementor.com/widget-' . $this->get_name(); |
| 273 |
} |
| 274 |
|
| 275 |
public function get_custom_help_url() { |
| 276 |
return ''; |
| 277 |
} |
| 278 |
|
| 279 |
/** |
| 280 |
* Whether the reload preview is required. |
| 281 |
* |
| 282 |
* Used to determine whether the reload preview is required or not. |
| 283 |
* |
| 284 |
* @since 1.0.0 |
| 285 |
* @access public |
| 286 |
* |
| 287 |
* @return bool Whether the reload preview is required. |
| 288 |
*/ |
| 289 |
public function is_reload_preview_required() { |
| 290 |
return false; |
| 291 |
} |
| 292 |
|
| 293 |
/** |
| 294 |
* @since 2.3.1 |
| 295 |
* @access protected |
| 296 |
*/ |
| 297 |
protected function should_print_empty() { |
| 298 |
return true; |
| 299 |
} |
| 300 |
|
| 301 |
/** |
| 302 |
* Get child elements. |
| 303 |
* |
| 304 |
* Retrieve all the child elements of this element. |
| 305 |
* |
| 306 |
* @since 1.0.0 |
| 307 |
* @access public |
| 308 |
* |
| 309 |
* @return Element_Base[] Child elements. |
| 310 |
*/ |
| 311 |
public function get_children() { |
| 312 |
if ( null === $this->children ) { |
| 313 |
$this->init_children(); |
| 314 |
} |
| 315 |
|
| 316 |
return $this->children; |
| 317 |
} |
| 318 |
|
| 319 |
/** |
| 320 |
* Get default arguments. |
| 321 |
* |
| 322 |
* Retrieve the element default arguments. Used to return all the default |
| 323 |
* arguments or a specific default argument, if one is set. |
| 324 |
* |
| 325 |
* @since 1.0.0 |
| 326 |
* @access public |
| 327 |
* |
| 328 |
* @param array $item Optional. Default is null. |
| 329 |
* |
| 330 |
* @return array Default argument(s). |
| 331 |
*/ |
| 332 |
public function get_default_args( $item = null ) { |
| 333 |
return self::get_items( $this->default_args, $item ); |
| 334 |
} |
| 335 |
|
| 336 |
/** |
| 337 |
* Add new child element. |
| 338 |
* |
| 339 |
* Register new child element to allow hierarchy. |
| 340 |
* |
| 341 |
* @since 1.0.0 |
| 342 |
* @access public |
| 343 |
* @param array $child_data Child element data. |
| 344 |
* @param array $child_args Child element arguments. |
| 345 |
* |
| 346 |
* @return Element_Base|false Child element instance, or false if failed. |
| 347 |
*/ |
| 348 |
public function add_child( array $child_data, array $child_args = [] ) { |
| 349 |
if ( null === $this->children ) { |
| 350 |
$this->init_children(); |
| 351 |
} |
| 352 |
|
| 353 |
$child_type = $this->get_child_type( $child_data ); |
| 354 |
|
| 355 |
if ( ! $child_type ) { |
| 356 |
return false; |
| 357 |
} |
| 358 |
|
| 359 |
$child = Plugin::$instance->elements_manager->create_element_instance( $child_data, $child_args, $child_type ); |
| 360 |
|
| 361 |
if ( $child ) { |
| 362 |
$this->children[] = $child; |
| 363 |
} |
| 364 |
|
| 365 |
return $child; |
| 366 |
} |
| 367 |
|
| 368 |
/** |
| 369 |
* Add render attribute. |
| 370 |
* |
| 371 |
* Used to add attributes to a specific HTML element. |
| 372 |
* |
| 373 |
* The HTML tag is represented by the element parameter, then you need to |
| 374 |
* define the attribute key and the attribute key. The final result will be: |
| 375 |
* `<element attribute_key="attribute_value">`. |
| 376 |
* |
| 377 |
* Example usage: |
| 378 |
* |
| 379 |
* `$this->add_render_attribute( 'wrapper', 'class', 'custom-widget-wrapper-class' );` |
| 380 |
* `$this->add_render_attribute( 'widget', 'id', 'custom-widget-id' );` |
| 381 |
* `$this->add_render_attribute( 'button', [ 'class' => 'custom-button-class', 'id' => 'custom-button-id' ] );` |
| 382 |
* |
| 383 |
* @since 1.0.0 |
| 384 |
* @access public |
| 385 |
* |
| 386 |
* @param array|string $element The HTML element. |
| 387 |
* @param array|string $key Optional. Attribute key. Default is null. |
| 388 |
* @param array|string $value Optional. Attribute value. Default is null. |
| 389 |
* @param bool $overwrite Optional. Whether to overwrite existing |
| 390 |
* attribute. Default is false, not to overwrite. |
| 391 |
* |
| 392 |
* @return Element_Base Current instance of the element. |
| 393 |
*/ |
| 394 |
public function add_render_attribute( $element, $key = null, $value = null, $overwrite = false ) { |
| 395 |
if ( is_array( $element ) ) { |
| 396 |
foreach ( $element as $element_key => $attributes ) { |
| 397 |
$this->add_render_attribute( $element_key, $attributes, null, $overwrite ); |
| 398 |
} |
| 399 |
|
| 400 |
return $this; |
| 401 |
} |
| 402 |
|
| 403 |
if ( is_array( $key ) ) { |
| 404 |
foreach ( $key as $attribute_key => $attributes ) { |
| 405 |
$this->add_render_attribute( $element, $attribute_key, $attributes, $overwrite ); |
| 406 |
} |
| 407 |
|
| 408 |
return $this; |
| 409 |
} |
| 410 |
|
| 411 |
if ( empty( $this->render_attributes[ $element ][ $key ] ) ) { |
| 412 |
$this->render_attributes[ $element ][ $key ] = []; |
| 413 |
} |
| 414 |
|
| 415 |
settype( $value, 'array' ); |
| 416 |
|
| 417 |
if ( $overwrite ) { |
| 418 |
$this->render_attributes[ $element ][ $key ] = $value; |
| 419 |
} else { |
| 420 |
$this->render_attributes[ $element ][ $key ] = array_merge( $this->render_attributes[ $element ][ $key ], $value ); |
| 421 |
} |
| 422 |
|
| 423 |
return $this; |
| 424 |
} |
| 425 |
|
| 426 |
/** |
| 427 |
* Add link render attributes. |
| 428 |
* |
| 429 |
* Used to add link tag attributes to a specific HTML element. |
| 430 |
* |
| 431 |
* The HTML link tag is represented by the element parameter. The `url_control` parameter |
| 432 |
* needs to be an array of link settings in the same format they are set by Elementor's URL control. |
| 433 |
* |
| 434 |
* Example usage: |
| 435 |
* |
| 436 |
* `$this->add_link_attributes( 'button', $settings['link'] );` |
| 437 |
* |
| 438 |
* @since 2.8.0 |
| 439 |
* @access public |
| 440 |
* |
| 441 |
* @param array|string $element The HTML element. |
| 442 |
* @param array $url_control Array of link settings. |
| 443 |
* @param bool $overwrite Optional. Whether to overwrite existing |
| 444 |
* attribute. Default is false, not to overwrite. |
| 445 |
* |
| 446 |
* @return Element_Base Current instance of the element. |
| 447 |
*/ |
| 448 |
|
| 449 |
public function add_link_attributes( $element, array $url_control, $overwrite = false ) { |
| 450 |
$attributes = []; |
| 451 |
|
| 452 |
if ( ! empty( $url_control['url'] ) ) { |
| 453 |
$allowed_protocols = array_merge( wp_allowed_protocols(), [ 'skype', 'viber' ] ); |
| 454 |
|
| 455 |
$attributes['href'] = esc_url( $url_control['url'], $allowed_protocols ); |
| 456 |
} |
| 457 |
|
| 458 |
if ( ! empty( $url_control['is_external'] ) ) { |
| 459 |
$attributes['target'] = '_blank'; |
| 460 |
} |
| 461 |
|
| 462 |
if ( ! empty( $url_control['nofollow'] ) ) { |
| 463 |
$attributes['rel'] = 'nofollow'; |
| 464 |
} |
| 465 |
|
| 466 |
if ( ! empty( $url_control['custom_attributes'] ) ) { |
| 467 |
// Custom URL attributes should come as a string of comma-delimited key|value pairs |
| 468 |
$attributes = array_merge( $attributes, Utils::parse_custom_attributes( $url_control['custom_attributes'] ) ); |
| 469 |
} |
| 470 |
|
| 471 |
if ( $attributes ) { |
| 472 |
$this->add_render_attribute( $element, $attributes, $overwrite ); |
| 473 |
} |
| 474 |
|
| 475 |
return $this; |
| 476 |
} |
| 477 |
|
| 478 |
/** |
| 479 |
* Get Render Attributes |
| 480 |
* |
| 481 |
* Used to retrieve render attribute. |
| 482 |
* |
| 483 |
* The returned array is either all elements and their attributes if no `$element` is specified, an array of all |
| 484 |
* attributes of a specific element or a specific attribute properties if `$key` is specified. |
| 485 |
* |
| 486 |
* Returns null if one of the requested parameters isn't set. |
| 487 |
* |
| 488 |
* @since 2.2.6 |
| 489 |
* @access public |
| 490 |
* @param string $element |
| 491 |
* @param string $key |
| 492 |
* |
| 493 |
* @return array |
| 494 |
*/ |
| 495 |
public function get_render_attributes( $element = '', $key = '' ) { |
| 496 |
$attributes = $this->render_attributes; |
| 497 |
|
| 498 |
if ( $element ) { |
| 499 |
if ( ! isset( $attributes[ $element ] ) ) { |
| 500 |
return null; |
| 501 |
} |
| 502 |
|
| 503 |
$attributes = $attributes[ $element ]; |
| 504 |
|
| 505 |
if ( $key ) { |
| 506 |
if ( ! isset( $attributes[ $key ] ) ) { |
| 507 |
return null; |
| 508 |
} |
| 509 |
|
| 510 |
$attributes = $attributes[ $key ]; |
| 511 |
} |
| 512 |
} |
| 513 |
|
| 514 |
return $attributes; |
| 515 |
} |
| 516 |
|
| 517 |
/** |
| 518 |
* Set render attribute. |
| 519 |
* |
| 520 |
* Used to set the value of the HTML element render attribute or to update |
| 521 |
* an existing render attribute. |
| 522 |
* |
| 523 |
* @since 1.0.0 |
| 524 |
* @access public |
| 525 |
* |
| 526 |
* @param array|string $element The HTML element. |
| 527 |
* @param array|string $key Optional. Attribute key. Default is null. |
| 528 |
* @param array|string $value Optional. Attribute value. Default is null. |
| 529 |
* |
| 530 |
* @return Element_Base Current instance of the element. |
| 531 |
*/ |
| 532 |
public function set_render_attribute( $element, $key = null, $value = null ) { |
| 533 |
return $this->add_render_attribute( $element, $key, $value, true ); |
| 534 |
} |
| 535 |
|
| 536 |
/** |
| 537 |
* Remove render attribute. |
| 538 |
* |
| 539 |
* Used to remove an element (with its keys and their values), key (with its values), |
| 540 |
* or value/s from an HTML element's render attribute. |
| 541 |
* |
| 542 |
* @since 2.7.0 |
| 543 |
* @access public |
| 544 |
* |
| 545 |
* @param string $element The HTML element. |
| 546 |
* @param string $key Optional. Attribute key. Default is null. |
| 547 |
* @param array|string $values Optional. Attribute value/s. Default is null. |
| 548 |
*/ |
| 549 |
public function remove_render_attribute( $element, $key = null, $values = null ) { |
| 550 |
if ( $key && ! isset( $this->render_attributes[ $element ][ $key ] ) ) { |
| 551 |
return; |
| 552 |
} |
| 553 |
|
| 554 |
if ( $values ) { |
| 555 |
$values = (array) $values; |
| 556 |
|
| 557 |
$this->render_attributes[ $element ][ $key ] = array_diff( $this->render_attributes[ $element ][ $key ], $values ); |
| 558 |
|
| 559 |
return; |
| 560 |
} |
| 561 |
|
| 562 |
if ( $key ) { |
| 563 |
unset( $this->render_attributes[ $element ][ $key ] ); |
| 564 |
|
| 565 |
return; |
| 566 |
} |
| 567 |
|
| 568 |
if ( isset( $this->render_attributes[ $element ] ) ) { |
| 569 |
unset( $this->render_attributes[ $element ] ); |
| 570 |
} |
| 571 |
} |
| 572 |
|
| 573 |
/** |
| 574 |
* Get render attribute string. |
| 575 |
* |
| 576 |
* Used to retrieve the value of the render attribute. |
| 577 |
* |
| 578 |
* @since 1.0.0 |
| 579 |
* @access public |
| 580 |
* |
| 581 |
* @param string $element The element. |
| 582 |
* |
| 583 |
* @return string Render attribute string, or an empty string if the attribute |
| 584 |
* is empty or not exist. |
| 585 |
*/ |
| 586 |
public function get_render_attribute_string( $element ) { |
| 587 |
if ( empty( $this->render_attributes[ $element ] ) ) { |
| 588 |
return ''; |
| 589 |
} |
| 590 |
|
| 591 |
return Utils::render_html_attributes( $this->render_attributes[ $element ] ); |
| 592 |
} |
| 593 |
|
| 594 |
/** |
| 595 |
* Print render attribute string. |
| 596 |
* |
| 597 |
* Used to output the rendered attribute. |
| 598 |
* |
| 599 |
* @since 2.0.0 |
| 600 |
* @access public |
| 601 |
* |
| 602 |
* @param array|string $element The element. |
| 603 |
*/ |
| 604 |
public function print_render_attribute_string( $element ) { |
| 605 |
echo $this->get_render_attribute_string( $element ); // XSS ok. |
| 606 |
} |
| 607 |
|
| 608 |
/** |
| 609 |
* Print element. |
| 610 |
* |
| 611 |
* Used to generate the element final HTML on the frontend and the editor. |
| 612 |
* |
| 613 |
* @since 1.0.0 |
| 614 |
* @access public |
| 615 |
*/ |
| 616 |
public function print_element() { |
| 617 |
$element_type = $this->get_type(); |
| 618 |
|
| 619 |
/** |
| 620 |
* Before frontend element render. |
| 621 |
* |
| 622 |
* Fires before Elementor element is rendered in the frontend. |
| 623 |
* |
| 624 |
* @since 2.2.0 |
| 625 |
* |
| 626 |
* @param Element_Base $this The element. |
| 627 |
*/ |
| 628 |
do_action( 'elementor/frontend/before_render', $this ); |
| 629 |
|
| 630 |
/** |
| 631 |
* Before frontend element render. |
| 632 |
* |
| 633 |
* Fires before Elementor element is rendered in the frontend. |
| 634 |
* |
| 635 |
* The dynamic portion of the hook name, `$element_type`, refers to the element type. |
| 636 |
* |
| 637 |
* @since 1.0.0 |
| 638 |
* |
| 639 |
* @param Element_Base $this The element. |
| 640 |
*/ |
| 641 |
do_action( "elementor/frontend/{$element_type}/before_render", $this ); |
| 642 |
|
| 643 |
ob_start(); |
| 644 |
|
| 645 |
if ( $this->has_own_method( '_print_content', self::class ) ) { |
| 646 |
Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( '_print_content', '3.1.0', __CLASS__ . '::print_content()' ); |
| 647 |
|
| 648 |
$this->_print_content(); |
| 649 |
} else { |
| 650 |
$this->print_content(); |
| 651 |
} |
| 652 |
|
| 653 |
$content = ob_get_clean(); |
| 654 |
|
| 655 |
$should_render = ( ! empty( $content ) || $this->should_print_empty() ); |
| 656 |
|
| 657 |
/** |
| 658 |
* Should the element be rendered for frontend |
| 659 |
* |
| 660 |
* Filters if the element should be rendered on frontend. |
| 661 |
* |
| 662 |
* @since 2.3.3 |
| 663 |
* |
| 664 |
* @param bool true The element. |
| 665 |
* @param Element_Base $this The element. |
| 666 |
*/ |
| 667 |
$should_render = apply_filters( "elementor/frontend/{$element_type}/should_render", $should_render, $this ); |
| 668 |
|
| 669 |
if ( $should_render ) { |
| 670 |
if ( $this->has_own_method( '_add_render_attributes', self::class ) ) { |
| 671 |
Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( '_add_render_attributes', '3.1.0', __CLASS__ . '::add_render_attributes()' ); |
| 672 |
|
| 673 |
$this->_add_render_attributes(); |
| 674 |
} else { |
| 675 |
$this->add_render_attributes(); |
| 676 |
} |
| 677 |
|
| 678 |
$this->before_render(); |
| 679 |
echo $content; |
| 680 |
$this->after_render(); |
| 681 |
|
| 682 |
$this->enqueue_scripts(); |
| 683 |
$this->enqueue_styles(); |
| 684 |
} |
| 685 |
|
| 686 |
/** |
| 687 |
* After frontend element render. |
| 688 |
* |
| 689 |
* Fires after Elementor element is rendered in the frontend. |
| 690 |
* |
| 691 |
* The dynamic portion of the hook name, `$element_type`, refers to the element type. |
| 692 |
* |
| 693 |
* @since 1.0.0 |
| 694 |
* |
| 695 |
* @param Element_Base $this The element. |
| 696 |
*/ |
| 697 |
do_action( "elementor/frontend/{$element_type}/after_render", $this ); |
| 698 |
|
| 699 |
/** |
| 700 |
* After frontend element render. |
| 701 |
* |
| 702 |
* Fires after Elementor element is rendered in the frontend. |
| 703 |
* |
| 704 |
* @since 2.3.0 |
| 705 |
* |
| 706 |
* @param Element_Base $this The element. |
| 707 |
*/ |
| 708 |
do_action( 'elementor/frontend/after_render', $this ); |
| 709 |
} |
| 710 |
|
| 711 |
/** |
| 712 |
* Get the element raw data. |
| 713 |
* |
| 714 |
* Retrieve the raw element data, including the id, type, settings, child |
| 715 |
* elements and whether it is an inner element. |
| 716 |
* |
| 717 |
* The data with the HTML used always to display the data, but the Elementor |
| 718 |
* editor uses the raw data without the HTML in order not to render the data |
| 719 |
* again. |
| 720 |
* |
| 721 |
* @since 1.0.0 |
| 722 |
* @access public |
| 723 |
* |
| 724 |
* @param bool $with_html_content Optional. Whether to return the data with |
| 725 |
* HTML content or without. Used for caching. |
| 726 |
* Default is false, without HTML. |
| 727 |
* |
| 728 |
* @return array Element raw data. |
| 729 |
*/ |
| 730 |
public function get_raw_data( $with_html_content = false ) { |
| 731 |
$data = $this->get_data(); |
| 732 |
|
| 733 |
$elements = []; |
| 734 |
|
| 735 |
foreach ( $this->get_children() as $child ) { |
| 736 |
$elements[] = $child->get_raw_data( $with_html_content ); |
| 737 |
} |
| 738 |
|
| 739 |
return [ |
| 740 |
'id' => $this->get_id(), |
| 741 |
'elType' => $data['elType'], |
| 742 |
'settings' => $data['settings'], |
| 743 |
'elements' => $elements, |
| 744 |
'isInner' => $data['isInner'], |
| 745 |
]; |
| 746 |
} |
| 747 |
|
| 748 |
/** |
| 749 |
* Get unique selector. |
| 750 |
* |
| 751 |
* Retrieve the unique selector of the element. Used to set a unique HTML |
| 752 |
* class for each HTML element. This way Elementor can set custom styles for |
| 753 |
* each element. |
| 754 |
* |
| 755 |
* @since 1.0.0 |
| 756 |
* @access public |
| 757 |
* |
| 758 |
* @return string Unique selector. |
| 759 |
*/ |
| 760 |
public function get_unique_selector() { |
| 761 |
return '.elementor-element-' . $this->get_id(); |
| 762 |
} |
| 763 |
|
| 764 |
/** |
| 765 |
* Is type instance. |
| 766 |
* |
| 767 |
* Used to determine whether the element is an instance of that type or not. |
| 768 |
* |
| 769 |
* @since 1.0.0 |
| 770 |
* @access public |
| 771 |
* |
| 772 |
* @return bool Whether the element is an instance of that type. |
| 773 |
*/ |
| 774 |
public function is_type_instance() { |
| 775 |
return $this->is_type_instance; |
| 776 |
} |
| 777 |
|
| 778 |
/** |
| 779 |
* Add render attributes. |
| 780 |
* |
| 781 |
* Used to add attributes to the current element wrapper HTML tag. |
| 782 |
* |
| 783 |
* @since 1.3.0 |
| 784 |
* @access protected |
| 785 |
* @deprecated 3.1.0 |
| 786 |
*/ |
| 787 |
protected function _add_render_attributes() { |
| 788 |
Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.1.0', __CLASS__ . '::add_render_attributes()' ); |
| 789 |
|
| 790 |
return $this->add_render_attributes(); |
| 791 |
} |
| 792 |
|
| 793 |
/** |
| 794 |
* Add render attributes. |
| 795 |
* |
| 796 |
* Used to add attributes to the current element wrapper HTML tag. |
| 797 |
* |
| 798 |
* @since 3.1.0 |
| 799 |
* @access protected |
| 800 |
*/ |
| 801 |
protected function add_render_attributes() { |
| 802 |
$id = $this->get_id(); |
| 803 |
|
| 804 |
$settings = $this->get_settings_for_display(); |
| 805 |
$frontend_settings = $this->get_frontend_settings(); |
| 806 |
$controls = $this->get_controls(); |
| 807 |
|
| 808 |
$this->add_render_attribute( '_wrapper', [ |
| 809 |
'class' => [ |
| 810 |
'elementor-element', |
| 811 |
'elementor-element-' . $id, |
| 812 |
], |
| 813 |
'data-id' => $id, |
| 814 |
'data-element_type' => $this->get_type(), |
| 815 |
] ); |
| 816 |
|
| 817 |
$class_settings = []; |
| 818 |
|
| 819 |
foreach ( $settings as $setting_key => $setting ) { |
| 820 |
if ( isset( $controls[ $setting_key ]['prefix_class'] ) ) { |
| 821 |
$class_settings[ $setting_key ] = $setting; |
| 822 |
} |
| 823 |
} |
| 824 |
|
| 825 |
foreach ( $class_settings as $setting_key => $setting ) { |
| 826 |
if ( empty( $setting ) && '0' !== $setting ) { |
| 827 |
continue; |
| 828 |
} |
| 829 |
|
| 830 |
$this->add_render_attribute( '_wrapper', 'class', $controls[ $setting_key ]['prefix_class'] . $setting ); |
| 831 |
} |
| 832 |
|
| 833 |
$_animation = ! empty( $settings['_animation'] ); |
| 834 |
$animation = ! empty( $settings['animation'] ); |
| 835 |
$has_animation = $_animation && 'none' !== $settings['_animation'] || $animation && 'none' !== $settings['animation']; |
| 836 |
|
| 837 |
if ( $has_animation ) { |
| 838 |
$is_static_render_mode = Plugin::$instance->frontend->is_static_render_mode(); |
| 839 |
|
| 840 |
if ( ! $is_static_render_mode ) { |
| 841 |
// Hide the element until the animation begins |
| 842 |
$this->add_render_attribute( '_wrapper', 'class', 'elementor-invisible' ); |
| 843 |
} |
| 844 |
} |
| 845 |
|
| 846 |
if ( ! empty( $settings['_element_id'] ) ) { |
| 847 |
$this->add_render_attribute( '_wrapper', 'id', trim( $settings['_element_id'] ) ); |
| 848 |
} |
| 849 |
|
| 850 |
if ( $frontend_settings ) { |
| 851 |
$this->add_render_attribute( '_wrapper', 'data-settings', wp_json_encode( $frontend_settings ) ); |
| 852 |
} |
| 853 |
|
| 854 |
/** |
| 855 |
* After element attribute rendered. |
| 856 |
* |
| 857 |
* Fires after the attributes of the element HTML tag are rendered. |
| 858 |
* |
| 859 |
* @since 2.3.0 |
| 860 |
* |
| 861 |
* @param Element_Base $this The element. |
| 862 |
*/ |
| 863 |
do_action( 'elementor/element/after_add_attributes', $this ); |
| 864 |
} |
| 865 |
|
| 866 |
/** |
| 867 |
* Get default data. |
| 868 |
* |
| 869 |
* Retrieve the default element data. Used to reset the data on initialization. |
| 870 |
* |
| 871 |
* @since 1.0.0 |
| 872 |
* @access protected |
| 873 |
* |
| 874 |
* @return array Default data. |
| 875 |
*/ |
| 876 |
protected function get_default_data() { |
| 877 |
$data = parent::get_default_data(); |
| 878 |
|
| 879 |
return array_merge( |
| 880 |
$data, [ |
| 881 |
'elements' => [], |
| 882 |
'isInner' => false, |
| 883 |
] |
| 884 |
); |
| 885 |
} |
| 886 |
|
| 887 |
/** |
| 888 |
* Print element content. |
| 889 |
* |
| 890 |
* Output the element final HTML on the frontend. |
| 891 |
* |
| 892 |
* @since 1.0.0 |
| 893 |
* @access protected |
| 894 |
*/ |
| 895 |
protected function _print_content() { |
| 896 |
Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.1.0', __CLASS__ . '::print_content()' ); |
| 897 |
|
| 898 |
$this->print_content(); |
| 899 |
} |
| 900 |
|
| 901 |
/** |
| 902 |
* Print element content. |
| 903 |
* |
| 904 |
* Output the element final HTML on the frontend. |
| 905 |
* |
| 906 |
* @since 3.1.0 |
| 907 |
* @access protected |
| 908 |
*/ |
| 909 |
protected function print_content() { |
| 910 |
foreach ( $this->get_children() as $child ) { |
| 911 |
$child->print_element(); |
| 912 |
} |
| 913 |
} |
| 914 |
|
| 915 |
/** |
| 916 |
* Get initial config. |
| 917 |
* |
| 918 |
* Retrieve the current element initial configuration. |
| 919 |
* |
| 920 |
* Adds more configuration on top of the controls list and the tabs assigned |
| 921 |
* to the control. This method also adds element name, type, icon and more. |
| 922 |
* |
| 923 |
* @since 2.9.0 |
| 924 |
* @access protected |
| 925 |
* |
| 926 |
* @return array The initial config. |
| 927 |
*/ |
| 928 |
protected function get_initial_config() { |
| 929 |
$config = [ |
| 930 |
'name' => $this->get_name(), |
| 931 |
'elType' => $this->get_type(), |
| 932 |
'title' => $this->get_title(), |
| 933 |
'icon' => $this->get_icon(), |
| 934 |
'reload_preview' => $this->is_reload_preview_required(), |
| 935 |
]; |
| 936 |
|
| 937 |
if ( preg_match( '/^' . __NAMESPACE__ . '(Pro)?\\\\/', get_called_class() ) ) { |
| 938 |
$config['help_url'] = $this->get_help_url(); |
| 939 |
} else { |
| 940 |
$config['help_url'] = $this->get_custom_help_url(); |
| 941 |
} |
| 942 |
|
| 943 |
if ( ! $this->is_editable() ) { |
| 944 |
$config['editable'] = false; |
| 945 |
} |
| 946 |
|
| 947 |
return $config; |
| 948 |
} |
| 949 |
|
| 950 |
/** |
| 951 |
* Get child type. |
| 952 |
* |
| 953 |
* Retrieve the element child type based on element data. |
| 954 |
* |
| 955 |
* @since 2.0.0 |
| 956 |
* @access private |
| 957 |
* |
| 958 |
* @param array $element_data Element ID. |
| 959 |
* |
| 960 |
* @return Element_Base|false Child type or false if type not found. |
| 961 |
*/ |
| 962 |
private function get_child_type( $element_data ) { |
| 963 |
$child_type = $this->_get_default_child_type( $element_data ); |
| 964 |
|
| 965 |
// If it's not a valid widget ( like a deactivated plugin ) |
| 966 |
if ( ! $child_type ) { |
| 967 |
return false; |
| 968 |
} |
| 969 |
|
| 970 |
/** |
| 971 |
* Element child type. |
| 972 |
* |
| 973 |
* Filters the child type of the element. |
| 974 |
* |
| 975 |
* @since 1.0.0 |
| 976 |
* |
| 977 |
* @param Element_Base $child_type The child element. |
| 978 |
* @param array $element_data The original element ID. |
| 979 |
* @param Element_Base $this The original element. |
| 980 |
*/ |
| 981 |
$child_type = apply_filters( 'elementor/element/get_child_type', $child_type, $element_data, $this ); |
| 982 |
|
| 983 |
return $child_type; |
| 984 |
} |
| 985 |
|
| 986 |
/** |
| 987 |
* Initialize children. |
| 988 |
* |
| 989 |
* Initializing the element child elements. |
| 990 |
* |
| 991 |
* @since 2.0.0 |
| 992 |
* @access private |
| 993 |
*/ |
| 994 |
private function init_children() { |
| 995 |
$this->children = []; |
| 996 |
|
| 997 |
$children_data = $this->get_data( 'elements' ); |
| 998 |
|
| 999 |
if ( ! $children_data ) { |
| 1000 |
return; |
| 1001 |
} |
| 1002 |
|
| 1003 |
foreach ( $children_data as $child_data ) { |
| 1004 |
if ( ! $child_data ) { |
| 1005 |
continue; |
| 1006 |
} |
| 1007 |
|
| 1008 |
$this->add_child( $child_data ); |
| 1009 |
} |
| 1010 |
} |
| 1011 |
|
| 1012 |
/** |
| 1013 |
* Element base constructor. |
| 1014 |
* |
| 1015 |
* Initializing the element base class using `$data` and `$args`. |
| 1016 |
* |
| 1017 |
* The `$data` parameter is required for a normal instance because of the |
| 1018 |
* way Elementor renders data when initializing elements. |
| 1019 |
* |
| 1020 |
* @since 1.0.0 |
| 1021 |
* @access public |
| 1022 |
* |
| 1023 |
* @param array $data Optional. Element data. Default is an empty array. |
| 1024 |
* @param array|null $args Optional. Element default arguments. Default is null. |
| 1025 |
**/ |
| 1026 |
public function __construct( array $data = [], array $args = null ) { |
| 1027 |
if ( $data ) { |
| 1028 |
$this->is_type_instance = false; |
| 1029 |
} elseif ( $args ) { |
| 1030 |
$this->default_args = $args; |
| 1031 |
} |
| 1032 |
|
| 1033 |
parent::__construct( $data ); |
| 1034 |
} |
| 1035 |
} |
| 1036 |
|