use Elementor\Core\Breakpoints\Manager as Breakpoints_Manager;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
* Elementor element base.
* An abstract class to register new Elementor elements. It extended the
* `Controls_Stack` class to inherit its properties.
* This abstract class must be extended in order to register new elements.
abstract class Element_Base extends Controls_Stack {
* Holds all the child elements of the element.
* Element default arguments.
* Holds all the default arguments of the element. Used to store additional
* data. For example WordPress widgets use this to store widget names.
private $default_args = [];
* Whether the element is an instance of that type or not.
private $is_type_instance = true;
* Holds all the element depended scripts to enqueue.
private $depended_scripts = [];
* Holds all the element depended styles to enqueue.
private $depended_styles = [];
* Register new script to enqueue by the handler.
* @param string $handler Depend script handler.
public function add_script_depends( $handler ) {
$this->depended_scripts[] = $handler;
* Register new style to enqueue by the handler.
* @param string $handler Depend style handler.
public function add_style_depends( $handler ) {
$this->depended_styles[] = $handler;
* Get script dependencies.
* Retrieve the list of script dependencies the element requires.
* @return array Element scripts dependencies.
public function get_script_depends() {
return $this->depended_scripts;
public function get_global_scripts() {
return [ 'elementor-frontend' ];
* Registers all the scripts defined as element dependencies and enqueues
* them. Use `get_script_depends()` method to add custom script dependencies.
final public function enqueue_scripts() {
// Insert here when you have a deprecated script.
foreach ( $this->get_script_depends() as $script ) {
if ( isset( $deprecated_scripts[ $script ] ) ) {
Utils::handle_deprecation( $script, $deprecated_scripts[ $script ]['version'], $deprecated_scripts[ $script ]['replacement'] );
wp_enqueue_script( $script );
foreach ( $this->get_global_scripts() as $script ) {
wp_enqueue_script( $script );
* Get style dependencies.
* Retrieve the list of style dependencies the element requires.
* @return array Element styles dependencies.
public function get_style_depends() {
return $this->depended_styles;
* Registers all the styles defined as element dependencies and enqueues
* them. Use `get_style_depends()` method to add custom style dependencies.
final public function enqueue_styles() {
foreach ( $this->get_style_depends() as $style ) {
wp_enqueue_style( $style );
final public static function add_edit_tool() {}
final public static function is_edit_buttons_enabled() {
return get_option( 'elementor_edit_buttons' );
* Get default child type.
* Retrieve the default child type based on element data.
* Note that not all elements support children.
* @param array $element_data Element data.
abstract protected function _get_default_child_type( array $element_data );
* Before element rendering.
* Used to add stuff before the element.
public function before_render() {}
* After element rendering.
* Used to add stuff after the element.
public function after_render() {}
* Retrieve the element title.
* @return string Element title.
public function get_title() {
* Retrieve the element icon.
* @return string Element icon.
public function get_icon() {
public function get_help_url() {
return 'https://go.elementor.com/widget-' . $this->get_name();
public function get_custom_help_url() {
* Whether the reload preview is required.
* Used to determine whether the reload preview is required or not.
* @return bool Whether the reload preview is required.
public function is_reload_preview_required() {
protected function should_print_empty() {
* Whether the element returns dynamic content.
* Set to determine whether to cache the element output or not.
* @return bool Whether to cache the element output.
protected function is_dynamic_content(): bool {
* Retrieve all the child elements of this element.
* @return Element_Base[] Child elements.
public function get_children() {
if ( null === $this->children ) {
* Retrieve the element default arguments. Used to return all the default
* arguments or a specific default argument, if one is set.
* @param array $item Optional. Default is null.
* @return array Default argument(s).
public function get_default_args( $item = null ) {
return self::get_items( $this->default_args, $item );
* Used for displaying the widget in the panel multiple times, but with different defaults values,
public function get_panel_presets() {
* Register new child element to allow hierarchy.
* @param array $child_data Child element data.
* @param array $child_args Child element arguments.
* @return Element_Base|false Child element instance, or false if failed.
public function add_child( array $child_data, array $child_args = [] ) {
if ( null === $this->children ) {
$child_type = $this->get_child_type( $child_data );
$child = Plugin::$instance->elements_manager->create_element_instance( $child_data, $child_args, $child_type );
$this->children[] = $child;
* Add link render attributes.
* Used to add link tag attributes to a specific HTML element.
* The HTML link tag is represented by the element parameter. The `url_control` parameter
* needs to be an array of link settings in the same format they are set by Elementor's URL control.
* `$this->add_link_attributes( 'button', $settings['link'] );`
* @param array|string $element The HTML element.
* @param array $url_control Array of link settings.
* @param bool $overwrite Optional. Whether to overwrite existing
* attribute. Default is false, not to overwrite.
* @return Element_Base Current instance of the element.
public function add_link_attributes( $element, array $url_control, $overwrite = false ) {
if ( ! empty( $url_control['url'] ) ) {
$allowed_protocols = array_merge( wp_allowed_protocols(), [ 'skype', 'viber' ] );
$attributes['href'] = esc_url( $url_control['url'], $allowed_protocols );
if ( ! empty( $url_control['is_external'] ) ) {
$attributes['target'] = '_blank';
if ( ! empty( $url_control['nofollow'] ) ) {
$attributes['rel'] = 'nofollow';
if ( ! empty( $url_control['custom_attributes'] ) ) {
// Custom URL attributes should come as a string of comma-delimited key|value pairs.
$attributes = array_merge( $attributes, Utils::parse_custom_attributes( $url_control['custom_attributes'] ) );
$this->add_render_attribute( $element, $attributes, null, $overwrite );
* Used to generate the element final HTML on the frontend and the editor.
public function print_element() {
$element_type = $this->get_type();
if ( $this->should_render_shortcode() ) {
$unique_id = apply_filters( 'elementor/element_cache/unique_id', '' );
echo '[elementor-element k="' . esc_attr( $unique_id ) . '" data="' . esc_attr( base64_encode( wp_json_encode( $this->get_raw_data() ) ) ) . '"]';
* Before frontend element render.
* Fires before Elementor element is rendered in the frontend.
* @param Element_Base $this The element.
do_action( 'elementor/frontend/before_render', $this );
* Before frontend element render.
* Fires before Elementor element is rendered in the frontend.
* The dynamic portion of the hook name, `$element_type`, refers to the element type.
* @param Element_Base $this The element.
do_action( "elementor/frontend/{$element_type}/before_render", $this );
if ( $this->has_own_method( '_print_content', self::class ) ) {
Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( '_print_content', '3.1.0', __CLASS__ . '::print_content()' );
$content = ob_get_clean();
$should_render = ( ! empty( $content ) || $this->should_print_empty() );
* Should the element be rendered for frontend