first commit
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,988 @@
|
||||
<?php
|
||||
namespace Elementor;
|
||||
|
||||
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.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @abstract
|
||||
*/
|
||||
abstract class Element_Base extends Controls_Stack {
|
||||
|
||||
/**
|
||||
* Child elements.
|
||||
*
|
||||
* Holds all the child elements of the element.
|
||||
*
|
||||
* @access private
|
||||
*
|
||||
* @var Element_Base[]
|
||||
*/
|
||||
private $children;
|
||||
|
||||
/**
|
||||
* Element render attributes.
|
||||
*
|
||||
* Holds all the render attributes of the element. Used to store data like
|
||||
* the HTML class name and the class value, or HTML element ID name and value.
|
||||
*
|
||||
* @access private
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $render_attributes = [];
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @access private
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $default_args = [];
|
||||
|
||||
/**
|
||||
* Is type instance.
|
||||
*
|
||||
* Whether the element is an instance of that type or not.
|
||||
*
|
||||
* @access private
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $is_type_instance = true;
|
||||
|
||||
/**
|
||||
* Depended scripts.
|
||||
*
|
||||
* Holds all the element depended scripts to enqueue.
|
||||
*
|
||||
* @since 1.9.0
|
||||
* @access private
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $depended_scripts = [];
|
||||
|
||||
/**
|
||||
* Depended styles.
|
||||
*
|
||||
* Holds all the element depended styles to enqueue.
|
||||
*
|
||||
* @since 1.9.0
|
||||
* @access private
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $depended_styles = [];
|
||||
|
||||
/**
|
||||
* Add script depends.
|
||||
*
|
||||
* Register new script to enqueue by the handler.
|
||||
*
|
||||
* @since 1.9.0
|
||||
* @access public
|
||||
*
|
||||
* @param string $handler Depend script handler.
|
||||
*/
|
||||
public function add_script_depends( $handler ) {
|
||||
$this->depended_scripts[] = $handler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add style depends.
|
||||
*
|
||||
* Register new style to enqueue by the handler.
|
||||
*
|
||||
* @since 1.9.0
|
||||
* @access public
|
||||
*
|
||||
* @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.
|
||||
*
|
||||
* @since 1.3.0
|
||||
* @access public
|
||||
*
|
||||
* @return array Element scripts dependencies.
|
||||
*/
|
||||
public function get_script_depends() {
|
||||
return $this->depended_scripts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue scripts.
|
||||
*
|
||||
* Registers all the scripts defined as element dependencies and enqueues
|
||||
* them. Use `get_script_depends()` method to add custom script dependencies.
|
||||
*
|
||||
* @since 1.3.0
|
||||
* @access public
|
||||
*/
|
||||
final public function enqueue_scripts() {
|
||||
$deprecated_scripts = [
|
||||
'jquery-slick' => [
|
||||
'version' => '2.7.0',
|
||||
'replacement' => 'Swiper',
|
||||
],
|
||||
];
|
||||
|
||||
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 );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get style dependencies.
|
||||
*
|
||||
* Retrieve the list of style dependencies the element requires.
|
||||
*
|
||||
* @since 1.9.0
|
||||
* @access public
|
||||
*
|
||||
* @return array Element styles dependencies.
|
||||
*/
|
||||
public function get_style_depends() {
|
||||
return $this->depended_styles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue styles.
|
||||
*
|
||||
* Registers all the styles defined as element dependencies and enqueues
|
||||
* them. Use `get_style_depends()` method to add custom style dependencies.
|
||||
*
|
||||
* @since 1.9.0
|
||||
* @access public
|
||||
*/
|
||||
final public function enqueue_styles() {
|
||||
foreach ( $this->get_style_depends() as $style ) {
|
||||
wp_enqueue_style( $style );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
* @deprecated 2.6.0
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
final public static function add_edit_tool() {}
|
||||
|
||||
/**
|
||||
* @since 2.2.0
|
||||
* @deprecated 2.6.0
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access protected
|
||||
* @abstract
|
||||
*
|
||||
* @param array $element_data Element data.
|
||||
*
|
||||
* @return Element_Base
|
||||
*/
|
||||
abstract protected function _get_default_child_type( array $element_data );
|
||||
|
||||
/**
|
||||
* Before element rendering.
|
||||
*
|
||||
* Used to add stuff before the element.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
*/
|
||||
public function before_render() {}
|
||||
|
||||
/**
|
||||
* After element rendering.
|
||||
*
|
||||
* Used to add stuff after the element.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
*/
|
||||
public function after_render() {}
|
||||
|
||||
/**
|
||||
* Get element title.
|
||||
*
|
||||
* Retrieve the element title.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
*
|
||||
* @return string Element title.
|
||||
*/
|
||||
public function get_title() {
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get element icon.
|
||||
*
|
||||
* Retrieve the element icon.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
*
|
||||
* @return string Element icon.
|
||||
*/
|
||||
public function get_icon() {
|
||||
return 'eicon-columns';
|
||||
}
|
||||
|
||||
public function get_help_url() {
|
||||
return 'https://go.elementor.com/widget-' . $this->get_name();
|
||||
}
|
||||
|
||||
public function get_custom_help_url() {
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the reload preview is required.
|
||||
*
|
||||
* Used to determine whether the reload preview is required or not.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
*
|
||||
* @return bool Whether the reload preview is required.
|
||||
*/
|
||||
public function is_reload_preview_required() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.3.1
|
||||
* @access protected
|
||||
*/
|
||||
protected function should_print_empty() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get child elements.
|
||||
*
|
||||
* Retrieve all the child elements of this element.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
*
|
||||
* @return Element_Base[] Child elements.
|
||||
*/
|
||||
public function get_children() {
|
||||
if ( null === $this->children ) {
|
||||
$this->init_children();
|
||||
}
|
||||
|
||||
return $this->children;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default arguments.
|
||||
*
|
||||
* Retrieve the element default arguments. Used to return all the default
|
||||
* arguments or a specific default argument, if one is set.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
*
|
||||
* @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 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add new child element.
|
||||
*
|
||||
* Register new child element to allow hierarchy.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
* @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 ) {
|
||||
$this->init_children();
|
||||
}
|
||||
|
||||
$child_type = $this->get_child_type( $child_data );
|
||||
|
||||
if ( ! $child_type ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$child = Plugin::$instance->elements_manager->create_element_instance( $child_data, $child_args, $child_type );
|
||||
|
||||
if ( $child ) {
|
||||
$this->children[] = $child;
|
||||
}
|
||||
|
||||
return $child;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add render attribute.
|
||||
*
|
||||
* Used to add attributes to a specific HTML element.
|
||||
*
|
||||
* The HTML tag is represented by the element parameter, then you need to
|
||||
* define the attribute key and the attribute key. The final result will be:
|
||||
* `<element attribute_key="attribute_value">`.
|
||||
*
|
||||
* Example usage:
|
||||
*
|
||||
* `$this->add_render_attribute( 'wrapper', 'class', 'custom-widget-wrapper-class' );`
|
||||
* `$this->add_render_attribute( 'widget', 'id', 'custom-widget-id' );`
|
||||
* `$this->add_render_attribute( 'button', [ 'class' => 'custom-button-class', 'id' => 'custom-button-id' ] );`
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
*
|
||||
* @param array|string $element The HTML element.
|
||||
* @param array|string $key Optional. Attribute key. Default is null.
|
||||
* @param array|string $value Optional. Attribute value. Default is null.
|
||||
* @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_render_attribute( $element, $key = null, $value = null, $overwrite = false ) {
|
||||
if ( is_array( $element ) ) {
|
||||
foreach ( $element as $element_key => $attributes ) {
|
||||
$this->add_render_attribute( $element_key, $attributes, null, $overwrite );
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
if ( is_array( $key ) ) {
|
||||
foreach ( $key as $attribute_key => $attributes ) {
|
||||
$this->add_render_attribute( $element, $attribute_key, $attributes, $overwrite );
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
if ( empty( $this->render_attributes[ $element ][ $key ] ) ) {
|
||||
$this->render_attributes[ $element ][ $key ] = [];
|
||||
}
|
||||
|
||||
settype( $value, 'array' );
|
||||
|
||||
if ( $overwrite ) {
|
||||
$this->render_attributes[ $element ][ $key ] = $value;
|
||||
} else {
|
||||
$this->render_attributes[ $element ][ $key ] = array_merge( $this->render_attributes[ $element ][ $key ], $value );
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* Example usage:
|
||||
*
|
||||
* `$this->add_link_attributes( 'button', $settings['link'] );`
|
||||
*
|
||||
* @since 2.8.0
|
||||
* @access public
|
||||
*
|
||||
* @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 ) {
|
||||
$attributes = [];
|
||||
|
||||
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'] ) );
|
||||
}
|
||||
|
||||
if ( $attributes ) {
|
||||
$this->add_render_attribute( $element, $attributes, $overwrite );
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Render Attributes
|
||||
*
|
||||
* Used to retrieve render attribute.
|
||||
*
|
||||
* The returned array is either all elements and their attributes if no `$element` is specified, an array of all
|
||||
* attributes of a specific element or a specific attribute properties if `$key` is specified.
|
||||
*
|
||||
* Returns null if one of the requested parameters isn't set.
|
||||
*
|
||||
* @since 2.2.6
|
||||
* @access public
|
||||
* @param string $element
|
||||
* @param string $key
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_render_attributes( $element = '', $key = '' ) {
|
||||
$attributes = $this->render_attributes;
|
||||
|
||||
if ( $element ) {
|
||||
if ( ! isset( $attributes[ $element ] ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$attributes = $attributes[ $element ];
|
||||
|
||||
if ( $key ) {
|
||||
if ( ! isset( $attributes[ $key ] ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$attributes = $attributes[ $key ];
|
||||
}
|
||||
}
|
||||
|
||||
return $attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set render attribute.
|
||||
*
|
||||
* Used to set the value of the HTML element render attribute or to update
|
||||
* an existing render attribute.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
*
|
||||
* @param array|string $element The HTML element.
|
||||
* @param array|string $key Optional. Attribute key. Default is null.
|
||||
* @param array|string $value Optional. Attribute value. Default is null.
|
||||
*
|
||||
* @return Element_Base Current instance of the element.
|
||||
*/
|
||||
public function set_render_attribute( $element, $key = null, $value = null ) {
|
||||
return $this->add_render_attribute( $element, $key, $value, true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove render attribute.
|
||||
*
|
||||
* Used to remove an element (with its keys and their values), key (with its values),
|
||||
* or value/s from an HTML element's render attribute.
|
||||
*
|
||||
* @since 2.7.0
|
||||
* @access public
|
||||
*
|
||||
* @param string $element The HTML element.
|
||||
* @param string $key Optional. Attribute key. Default is null.
|
||||
* @param array|string $values Optional. Attribute value/s. Default is null.
|
||||
*/
|
||||
public function remove_render_attribute( $element, $key = null, $values = null ) {
|
||||
if ( $key && ! isset( $this->render_attributes[ $element ][ $key ] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( $values ) {
|
||||
$values = (array) $values;
|
||||
|
||||
$this->render_attributes[ $element ][ $key ] = array_diff( $this->render_attributes[ $element ][ $key ], $values );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ( $key ) {
|
||||
unset( $this->render_attributes[ $element ][ $key ] );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ( isset( $this->render_attributes[ $element ] ) ) {
|
||||
unset( $this->render_attributes[ $element ] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get render attribute string.
|
||||
*
|
||||
* Used to retrieve the value of the render attribute.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
*
|
||||
* @param string $element The element.
|
||||
*
|
||||
* @return string Render attribute string, or an empty string if the attribute
|
||||
* is empty or not exist.
|
||||
*/
|
||||
public function get_render_attribute_string( $element ) {
|
||||
if ( empty( $this->render_attributes[ $element ] ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return Utils::render_html_attributes( $this->render_attributes[ $element ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Print render attribute string.
|
||||
*
|
||||
* Used to output the rendered attribute.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
*
|
||||
* @param array|string $element The element.
|
||||
*/
|
||||
public function print_render_attribute_string( $element ) {
|
||||
echo $this->get_render_attribute_string( $element ); // XSS ok.
|
||||
}
|
||||
|
||||
/**
|
||||
* Print element.
|
||||
*
|
||||
* Used to generate the element final HTML on the frontend and the editor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
*/
|
||||
public function print_element() {
|
||||
$element_type = $this->get_type();
|
||||
|
||||
/**
|
||||
* Before frontend element render.
|
||||
*
|
||||
* Fires before Elementor element is rendered in the frontend.
|
||||
*
|
||||
* @since 2.2.0
|
||||
*
|
||||
* @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.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param Element_Base $this The element.
|
||||
*/
|
||||
do_action( "elementor/frontend/{$element_type}/before_render", $this );
|
||||
|
||||
ob_start();
|
||||
$this->_print_content();
|
||||
$content = ob_get_clean();
|
||||
|
||||
$should_render = ( ! empty( $content ) || $this->should_print_empty() );
|
||||
|
||||
/**
|
||||
* Should the element be rendered for frontend
|
||||
*
|
||||
* Filters if the element should be rendered on frontend.
|
||||
*
|
||||
* @since 2.3.3
|
||||
*
|
||||
* @param bool true The element.
|
||||
* @param Element_Base $this The element.
|
||||
*/
|
||||
$should_render = apply_filters( "elementor/frontend/{$element_type}/should_render", $should_render, $this );
|
||||
|
||||
if ( $should_render ) {
|
||||
$this->_add_render_attributes();
|
||||
|
||||
$this->before_render();
|
||||
echo $content;
|
||||
$this->after_render();
|
||||
|
||||
$this->enqueue_scripts();
|
||||
$this->enqueue_styles();
|
||||
}
|
||||
|
||||
/**
|
||||
* After frontend element render.
|
||||
*
|
||||
* Fires after Elementor element is rendered in the frontend.
|
||||
*
|
||||
* The dynamic portion of the hook name, `$element_type`, refers to the element type.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param Element_Base $this The element.
|
||||
*/
|
||||
do_action( "elementor/frontend/{$element_type}/after_render", $this );
|
||||
|
||||
/**
|
||||
* After frontend element render.
|
||||
*
|
||||
* Fires after Elementor element is rendered in the frontend.
|
||||
*
|
||||
* @since 2.3.0
|
||||
*
|
||||
* @param Element_Base $this The element.
|
||||
*/
|
||||
do_action( 'elementor/frontend/after_render', $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the element raw data.
|
||||
*
|
||||
* Retrieve the raw element data, including the id, type, settings, child
|
||||
* elements and whether it is an inner element.
|
||||
*
|
||||
* The data with the HTML used always to display the data, but the Elementor
|
||||
* editor uses the raw data without the HTML in order not to render the data
|
||||
* again.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
*
|
||||
* @param bool $with_html_content Optional. Whether to return the data with
|
||||
* HTML content or without. Used for caching.
|
||||
* Default is false, without HTML.
|
||||
*
|
||||
* @return array Element raw data.
|
||||
*/
|
||||
public function get_raw_data( $with_html_content = false ) {
|
||||
$data = $this->get_data();
|
||||
|
||||
$elements = [];
|
||||
|
||||
foreach ( $this->get_children() as $child ) {
|
||||
$elements[] = $child->get_raw_data( $with_html_content );
|
||||
}
|
||||
|
||||
return [
|
||||
'id' => $this->get_id(),
|
||||
'elType' => $data['elType'],
|
||||
'settings' => $data['settings'],
|
||||
'elements' => $elements,
|
||||
'isInner' => $data['isInner'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get unique selector.
|
||||
*
|
||||
* Retrieve the unique selector of the element. Used to set a unique HTML
|
||||
* class for each HTML element. This way Elementor can set custom styles for
|
||||
* each element.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
*
|
||||
* @return string Unique selector.
|
||||
*/
|
||||
public function get_unique_selector() {
|
||||
return '.elementor-element-' . $this->get_id();
|
||||
}
|
||||
|
||||
/**
|
||||
* Is type instance.
|
||||
*
|
||||
* Used to determine whether the element is an instance of that type or not.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
*
|
||||
* @return bool Whether the element is an instance of that type.
|
||||
*/
|
||||
public function is_type_instance() {
|
||||
return $this->is_type_instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add render attributes.
|
||||
*
|
||||
* Used to add attributes to the current element wrapper HTML tag.
|
||||
*
|
||||
* @since 1.3.0
|
||||
* @access protected
|
||||
*/
|
||||
protected function _add_render_attributes() {
|
||||
$id = $this->get_id();
|
||||
|
||||
$settings = $this->get_settings_for_display();
|
||||
$frontend_settings = $this->get_frontend_settings();
|
||||
$controls = $this->get_controls();
|
||||
|
||||
$this->add_render_attribute( '_wrapper', [
|
||||
'class' => [
|
||||
'elementor-element',
|
||||
'elementor-element-' . $id,
|
||||
],
|
||||
'data-id' => $id,
|
||||
'data-element_type' => $this->get_type(),
|
||||
] );
|
||||
|
||||
$class_settings = [];
|
||||
|
||||
foreach ( $settings as $setting_key => $setting ) {
|
||||
if ( isset( $controls[ $setting_key ]['prefix_class'] ) ) {
|
||||
$class_settings[ $setting_key ] = $setting;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( $class_settings as $setting_key => $setting ) {
|
||||
if ( empty( $setting ) && '0' !== $setting ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->add_render_attribute( '_wrapper', 'class', $controls[ $setting_key ]['prefix_class'] . $setting );
|
||||
}
|
||||
|
||||
if ( ! empty( $settings['animation'] ) || ! empty( $settings['_animation'] ) ) {
|
||||
$is_static_render_mode = Plugin::$instance->frontend->is_static_render_mode();
|
||||
|
||||
if ( ! $is_static_render_mode ) {
|
||||
// Hide the element until the animation begins
|
||||
$this->add_render_attribute( '_wrapper', 'class', 'elementor-invisible' );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $settings['_element_id'] ) ) {
|
||||
$this->add_render_attribute( '_wrapper', 'id', trim( $settings['_element_id'] ) );
|
||||
}
|
||||
|
||||
if ( $frontend_settings ) {
|
||||
$this->add_render_attribute( '_wrapper', 'data-settings', wp_json_encode( $frontend_settings ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* After element attribute rendered.
|
||||
*
|
||||
* Fires after the attributes of the element HTML tag are rendered.
|
||||
*
|
||||
* @since 2.3.0
|
||||
*
|
||||
* @param Element_Base $this The element.
|
||||
*/
|
||||
do_action( 'elementor/element/after_add_attributes', $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default data.
|
||||
*
|
||||
* Retrieve the default element data. Used to reset the data on initialization.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access protected
|
||||
*
|
||||
* @return array Default data.
|
||||
*/
|
||||
protected function get_default_data() {
|
||||
$data = parent::get_default_data();
|
||||
|
||||
return array_merge(
|
||||
$data, [
|
||||
'elements' => [],
|
||||
'isInner' => false,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Print element content.
|
||||
*
|
||||
* Output the element final HTML on the frontend.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access protected
|
||||
*/
|
||||
protected function _print_content() {
|
||||
foreach ( $this->get_children() as $child ) {
|
||||
$child->print_element();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get initial config.
|
||||
*
|
||||
* Retrieve the current element initial configuration.
|
||||
*
|
||||
* Adds more configuration on top of the controls list and the tabs assigned
|
||||
* to the control. This method also adds element name, type, icon and more.
|
||||
*
|
||||
* @since 2.9.0
|
||||
* @access protected
|
||||
*
|
||||
* @return array The initial config.
|
||||
*/
|
||||
protected function get_initial_config() {
|
||||
$config = [
|
||||
'name' => $this->get_name(),
|
||||
'elType' => $this->get_type(),
|
||||
'title' => $this->get_title(),
|
||||
'icon' => $this->get_icon(),
|
||||
'reload_preview' => $this->is_reload_preview_required(),
|
||||
];
|
||||
|
||||
if ( preg_match( '/^' . __NAMESPACE__ . '(Pro)?\\\\/', get_called_class() ) ) {
|
||||
$config['help_url'] = $this->get_help_url();
|
||||
} else {
|
||||
$config['help_url'] = $this->get_custom_help_url();
|
||||
}
|
||||
|
||||
if ( ! $this->is_editable() ) {
|
||||
$config['editable'] = false;
|
||||
}
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get child type.
|
||||
*
|
||||
* Retrieve the element child type based on element data.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access private
|
||||
*
|
||||
* @param array $element_data Element ID.
|
||||
*
|
||||
* @return Element_Base|false Child type or false if type not found.
|
||||
*/
|
||||
private function get_child_type( $element_data ) {
|
||||
$child_type = $this->_get_default_child_type( $element_data );
|
||||
|
||||
// If it's not a valid widget ( like a deactivated plugin )
|
||||
if ( ! $child_type ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Element child type.
|
||||
*
|
||||
* Filters the child type of the element.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param Element_Base $child_type The child element.
|
||||
* @param array $element_data The original element ID.
|
||||
* @param Element_Base $this The original element.
|
||||
*/
|
||||
$child_type = apply_filters( 'elementor/element/get_child_type', $child_type, $element_data, $this );
|
||||
|
||||
return $child_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize children.
|
||||
*
|
||||
* Initializing the element child elements.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access private
|
||||
*/
|
||||
private function init_children() {
|
||||
$this->children = [];
|
||||
|
||||
$children_data = $this->get_data( 'elements' );
|
||||
|
||||
if ( ! $children_data ) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ( $children_data as $child_data ) {
|
||||
if ( ! $child_data ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->add_child( $child_data );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Element base constructor.
|
||||
*
|
||||
* Initializing the element base class using `$data` and `$args`.
|
||||
*
|
||||
* The `$data` parameter is required for a normal instance because of the
|
||||
* way Elementor renders data when initializing elements.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
*
|
||||
* @param array $data Optional. Element data. Default is an empty array.
|
||||
* @param array|null $args Optional. Element default arguments. Default is null.
|
||||
**/
|
||||
public function __construct( array $data = [], array $args = null ) {
|
||||
if ( $data ) {
|
||||
$this->is_type_instance = false;
|
||||
} elseif ( $args ) {
|
||||
$this->default_args = $args;
|
||||
}
|
||||
|
||||
parent::__construct( $data );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,249 @@
|
||||
<?php
|
||||
namespace Elementor;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
/**
|
||||
* Elementor skin base.
|
||||
*
|
||||
* An abstract class to register new skins for Elementor widgets. Skins allows
|
||||
* you to add new templates, set custom controls and more.
|
||||
*
|
||||
* To register new skins for your widget use the `add_skin()` method inside the
|
||||
* widget's `_register_skins()` method.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @abstract
|
||||
*/
|
||||
abstract class Skin_Base extends Sub_Controls_Stack {
|
||||
|
||||
/**
|
||||
* Parent widget.
|
||||
*
|
||||
* Holds the parent widget of the skin. Default value is null, no parent widget.
|
||||
*
|
||||
* @access protected
|
||||
*
|
||||
* @var Widget_Base|null
|
||||
*/
|
||||
protected $parent = null;
|
||||
|
||||
/**
|
||||
* Skin base constructor.
|
||||
*
|
||||
* Initializing the skin base class by setting parent widget and registering
|
||||
* controls actions.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
* @param Widget_Base $parent
|
||||
*/
|
||||
public function __construct( Widget_Base $parent ) {
|
||||
parent::__construct( $parent );
|
||||
|
||||
$this->_register_controls_actions();
|
||||
}
|
||||
|
||||
/**
|
||||
* Render skin.
|
||||
*
|
||||
* Generates the final HTML on the frontend.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
* @abstract
|
||||
*/
|
||||
abstract public function render();
|
||||
|
||||
/**
|
||||
* Register skin controls actions.
|
||||
*
|
||||
* Run on init and used to register new skins to be injected to the widget.
|
||||
* This method is used to register new actions that specify the location of
|
||||
* the skin in the widget.
|
||||
*
|
||||
* Example usage:
|
||||
* `add_action( 'elementor/element/{widget_id}/{section_id}/before_section_end', [ $this, 'register_controls' ] );`
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access protected
|
||||
*/
|
||||
protected function _register_controls_actions() {}
|
||||
|
||||
/**
|
||||
* Get skin control ID.
|
||||
*
|
||||
* Retrieve the skin control ID. Note that skin controls have special prefix
|
||||
* to distinguish them from regular controls, and from controls in other
|
||||
* skins.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access protected
|
||||
*
|
||||
* @param string $control_base_id Control base ID.
|
||||
*
|
||||
* @return string Control ID.
|
||||
*/
|
||||
protected function get_control_id( $control_base_id ) {
|
||||
$skin_id = str_replace( '-', '_', $this->get_id() );
|
||||
return $skin_id . '_' . $control_base_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get skin settings.
|
||||
*
|
||||
* Retrieve all the skin settings or, when requested, a specific setting.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @TODO: rename to get_setting() and create backward compatibility.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param string $control_base_id Control base ID.
|
||||
*
|
||||
* @return Widget_Base Widget instance.
|
||||
*/
|
||||
public function get_instance_value( $control_base_id ) {
|
||||
$control_id = $this->get_control_id( $control_base_id );
|
||||
return $this->parent->get_settings( $control_id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Start skin controls section.
|
||||
*
|
||||
* Used to add a new section of controls to the skin.
|
||||
*
|
||||
* @since 1.3.0
|
||||
* @access public
|
||||
*
|
||||
* @param string $id Section ID.
|
||||
* @param array $args Section arguments.
|
||||
*/
|
||||
public function start_controls_section( $id, $args = [] ) {
|
||||
$args['condition']['_skin'] = $this->get_id();
|
||||
parent::start_controls_section( $id, $args );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add new skin control.
|
||||
*
|
||||
* Register a single control to the allow the user to set/update skin data.
|
||||
*
|
||||
* @param string $id Control ID.
|
||||
* @param array $args Control arguments.
|
||||
* @param array $options
|
||||
*
|
||||
* @return bool True if skin added, False otherwise.
|
||||
|
||||
* @since 3.0.0 New `$options` parameter added.
|
||||
* @access public
|
||||
*
|
||||
*/
|
||||
public function add_control( $id, $args = [], $options = [] ) {
|
||||
$args['condition']['_skin'] = $this->get_id();
|
||||
return parent::add_control( $id, $args, $options );
|
||||
}
|
||||
|
||||
/**
|
||||
* Update skin control.
|
||||
*
|
||||
* Change the value of an existing skin control.
|
||||
*
|
||||
* @since 1.3.0
|
||||
* @since 1.8.1 New `$options` parameter added.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param string $id Control ID.
|
||||
* @param array $args Control arguments. Only the new fields you want to update.
|
||||
* @param array $options Optional. Some additional options.
|
||||
*/
|
||||
public function update_control( $id, $args, array $options = [] ) {
|
||||
$args['condition']['_skin'] = $this->get_id();
|
||||
parent::update_control( $id, $args, $options );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add new responsive skin control.
|
||||
*
|
||||
* Register a set of controls to allow editing based on user screen size.
|
||||
*
|
||||
* @param string $id Responsive control ID.
|
||||
* @param array $args Responsive control arguments.
|
||||
* @param array $options
|
||||
*
|
||||
* @since 1.0.5
|
||||
* @access public
|
||||
*
|
||||
*/
|
||||
public function add_responsive_control( $id, $args, $options = [] ) {
|
||||
$args['condition']['_skin'] = $this->get_id();
|
||||
parent::add_responsive_control( $id, $args );
|
||||
}
|
||||
|
||||
/**
|
||||
* Start skin controls tab.
|
||||
*
|
||||
* Used to add a new tab inside a group of tabs.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @access public
|
||||
*
|
||||
* @param string $id Control ID.
|
||||
* @param array $args Control arguments.
|
||||
*/
|
||||
public function start_controls_tab( $id, $args ) {
|
||||
$args['condition']['_skin'] = $this->get_id();
|
||||
parent::start_controls_tab( $id, $args );
|
||||
}
|
||||
|
||||
/**
|
||||
* Start skin controls tabs.
|
||||
*
|
||||
* Used to add a new set of tabs inside a section.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @access public
|
||||
*
|
||||
* @param string $id Control ID.
|
||||
*/
|
||||
public function start_controls_tabs( $id ) {
|
||||
$args['condition']['_skin'] = $this->get_id();
|
||||
parent::start_controls_tabs( $id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add new group control.
|
||||
*
|
||||
* Register a set of related controls grouped together as a single unified
|
||||
* control.
|
||||
*
|
||||
* @param string $group_name Group control name.
|
||||
* @param array $args Group control arguments. Default is an empty array.
|
||||
* @param array $options
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
*
|
||||
*/
|
||||
final public function add_group_control( $group_name, $args = [], $options = [] ) {
|
||||
$args['condition']['_skin'] = $this->get_id();
|
||||
parent::add_group_control( $group_name, $args );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set parent widget.
|
||||
*
|
||||
* Used to define the parent widget of the skin.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
*
|
||||
* @param Widget_Base $parent Parent widget.
|
||||
*/
|
||||
public function set_parent( $parent ) {
|
||||
$this->parent = $parent;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,242 @@
|
||||
<?php
|
||||
namespace Elementor;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
/**
|
||||
* Elementor sub controls stack.
|
||||
*
|
||||
* An abstract class that can be used to divide a large ControlsStack into small parts.
|
||||
*
|
||||
* @abstract
|
||||
*/
|
||||
abstract class Sub_Controls_Stack {
|
||||
/**
|
||||
* @var Controls_Stack
|
||||
*/
|
||||
protected $parent;
|
||||
|
||||
/**
|
||||
* Get self ID.
|
||||
*
|
||||
* Retrieve the self ID.
|
||||
*
|
||||
* @access public
|
||||
* @abstract
|
||||
*/
|
||||
abstract public function get_id();
|
||||
|
||||
/**
|
||||
* Get self title.
|
||||
*
|
||||
* Retrieve the self title.
|
||||
*
|
||||
* @access public
|
||||
* @abstract
|
||||
*/
|
||||
abstract public function get_title();
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* Initializing the base class by setting parent stack.
|
||||
*
|
||||
* @access public
|
||||
* @param Controls_Stack $parent
|
||||
*/
|
||||
public function __construct( $parent ) {
|
||||
$this->parent = $parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get control ID.
|
||||
*
|
||||
* Retrieve the control ID. Note that the sub controls stack may have a special prefix
|
||||
* to distinguish them from regular controls, and from controls in other
|
||||
* sub stack.
|
||||
*
|
||||
* By default do nothing, and return the original id.
|
||||
*
|
||||
* @access protected
|
||||
*
|
||||
* @param string $control_base_id Control base ID.
|
||||
*
|
||||
* @return string Control ID.
|
||||
*/
|
||||
protected function get_control_id( $control_base_id ) {
|
||||
return $control_base_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add new control.
|
||||
*
|
||||
* Register a single control to allow the user to set/update data.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param string $id Control ID.
|
||||
* @param array $args Control arguments.
|
||||
* @param array $options
|
||||
*
|
||||
* @return bool True if added, False otherwise.
|
||||
*/
|
||||
public function add_control( $id, $args, $options = [] ) {
|
||||
return $this->parent->add_control( $this->get_control_id( $id ), $args, $options );
|
||||
}
|
||||
|
||||
/**
|
||||
* Update control.
|
||||
*
|
||||
* Change the value of an existing control.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param string $id Control ID.
|
||||
* @param array $args Control arguments. Only the new fields you want to update.
|
||||
* @param array $options Optional. Some additional options.
|
||||
*/
|
||||
public function update_control( $id, $args, array $options = [] ) {
|
||||
$this->parent->update_control( $this->get_control_id( $id ), $args, $options );
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove control.
|
||||
*
|
||||
* Unregister an existing control.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param string $id Control ID.
|
||||
*/
|
||||
public function remove_control( $id ) {
|
||||
$this->parent->remove_control( $this->get_control_id( $id ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add new group control.
|
||||
*
|
||||
* Register a set of related controls grouped together as a single unified
|
||||
* control.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param string $group_name Group control name.
|
||||
* @param array $args Group control arguments. Default is an empty array.
|
||||
* @param array $options
|
||||
*
|
||||
*/
|
||||
public function add_group_control( $group_name, $args, $options = [] ) {
|
||||
$args['name'] = $this->get_control_id( $args['name'] );
|
||||
$this->parent->add_group_control( $group_name, $args, $options );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add new responsive control.
|
||||
*
|
||||
* Register a set of controls to allow editing based on user screen size.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param string $id Responsive control ID.
|
||||
* @param array $args Responsive control arguments.
|
||||
* @param array $options
|
||||
*/
|
||||
public function add_responsive_control( $id, $args, $options = [] ) {
|
||||
$this->parent->add_responsive_control( $this->get_control_id( $id ), $args, $options );
|
||||
}
|
||||
|
||||
/**
|
||||
* Update responsive control.
|
||||
*
|
||||
* Change the value of an existing responsive control.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param string $id Responsive control ID.
|
||||
* @param array $args Responsive control arguments.
|
||||
*/
|
||||
public function update_responsive_control( $id, $args ) {
|
||||
$this->parent->update_responsive_control( $this->get_control_id( $id ), $args );
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove responsive control.
|
||||
*
|
||||
* Unregister an existing responsive control.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param string $id Responsive control ID.
|
||||
*/
|
||||
public function remove_responsive_control( $id ) {
|
||||
$this->parent->remove_responsive_control( $this->get_control_id( $id ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Start controls section.
|
||||
*
|
||||
* Used to add a new section of controls to the stack.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param string $id Section ID.
|
||||
* @param array $args Section arguments.
|
||||
*/
|
||||
|
||||
public function start_controls_section( $id, $args = [] ) {
|
||||
$this->parent->start_controls_section( $this->get_control_id( $id ), $args );
|
||||
}
|
||||
|
||||
/**
|
||||
* End controls section.
|
||||
*
|
||||
* Used to close an existing open controls section.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function end_controls_section() {
|
||||
$this->parent->end_controls_section();
|
||||
}
|
||||
|
||||
/**
|
||||
* Start controls tabs.
|
||||
*
|
||||
* Used to add a new set of tabs inside a section.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param string $id Control ID.
|
||||
*/
|
||||
public function start_controls_tabs( $id ) {
|
||||
$this->parent->start_controls_tabs( $this->get_control_id( $id ) );
|
||||
}
|
||||
|
||||
public function start_controls_tab( $id, $args ) {
|
||||
$this->parent->start_controls_tab( $this->get_control_id( $id ), $args );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* End controls tabs.
|
||||
*
|
||||
* Used to close an existing open controls tabs.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function end_controls_tab() {
|
||||
$this->parent->end_controls_tab();
|
||||
}
|
||||
|
||||
/**
|
||||
* End controls tabs.
|
||||
*
|
||||
* Used to close an existing open controls tabs.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function end_controls_tabs() {
|
||||
$this->parent->end_controls_tabs();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,887 @@
|
||||
<?php
|
||||
namespace Elementor;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
/**
|
||||
* Elementor widget base.
|
||||
*
|
||||
* An abstract class to register new Elementor widgets. It extended the
|
||||
* `Element_Base` class to inherit its properties.
|
||||
*
|
||||
* This abstract class must be extended in order to register new widgets.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @abstract
|
||||
*/
|
||||
abstract class Widget_Base extends Element_Base {
|
||||
|
||||
/**
|
||||
* Whether the widget has content.
|
||||
*
|
||||
* Used in cases where the widget has no content. When widgets uses only
|
||||
* skins to display dynamic content generated on the server. For example the
|
||||
* posts widget in Elementor Pro. Default is true, the widget has content
|
||||
* template.
|
||||
*
|
||||
* @access protected
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $_has_template_content = true;
|
||||
|
||||
/**
|
||||
* Get element type.
|
||||
*
|
||||
* Retrieve the element type, in this case `widget`.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
* @static
|
||||
*
|
||||
* @return string The type.
|
||||
*/
|
||||
public static function get_type() {
|
||||
return 'widget';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get widget icon.
|
||||
*
|
||||
* Retrieve the widget icon.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
*
|
||||
* @return string Widget icon.
|
||||
*/
|
||||
public function get_icon() {
|
||||
return 'eicon-apps';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get widget keywords.
|
||||
*
|
||||
* Retrieve the widget keywords.
|
||||
*
|
||||
* @since 1.0.10
|
||||
* @access public
|
||||
*
|
||||
* @return array Widget keywords.
|
||||
*/
|
||||
public function get_keywords() {
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get widget categories.
|
||||
*
|
||||
* Retrieve the widget categories.
|
||||
*
|
||||
* @since 1.0.10
|
||||
* @access public
|
||||
*
|
||||
* @return array Widget categories.
|
||||
*/
|
||||
public function get_categories() {
|
||||
return [ 'general' ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Widget base constructor.
|
||||
*
|
||||
* Initializing the widget base class.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
*
|
||||
* @throws \Exception If arguments are missing when initializing a full widget
|
||||
* instance.
|
||||
*
|
||||
* @param array $data Widget data. Default is an empty array.
|
||||
* @param array|null $args Optional. Widget default arguments. Default is null.
|
||||
*/
|
||||
public function __construct( $data = [], $args = null ) {
|
||||
parent::__construct( $data, $args );
|
||||
|
||||
$is_type_instance = $this->is_type_instance();
|
||||
|
||||
if ( ! $is_type_instance && null === $args ) {
|
||||
throw new \Exception( '`$args` argument is required when initializing a full widget instance.' );
|
||||
}
|
||||
|
||||
if ( $is_type_instance ) {
|
||||
$this->_register_skins();
|
||||
|
||||
$widget_name = $this->get_name();
|
||||
/**
|
||||
* Widget skin init.
|
||||
*
|
||||
* Fires when Elementor widget is being initialized.
|
||||
*
|
||||
* The dynamic portion of the hook name, `$widget_name`, refers to the widget name.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param Widget_Base $this The current widget.
|
||||
*/
|
||||
do_action( "elementor/widget/{$widget_name}/skins_init", $this );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get stack.
|
||||
*
|
||||
* Retrieve the widget stack of controls.
|
||||
*
|
||||
* @since 1.9.2
|
||||
* @access public
|
||||
*
|
||||
* @param bool $with_common_controls Optional. Whether to include the common controls. Default is true.
|
||||
*
|
||||
* @return array Widget stack of controls.
|
||||
*/
|
||||
public function get_stack( $with_common_controls = true ) {
|
||||
$stack = parent::get_stack();
|
||||
|
||||
if ( $with_common_controls && 'common' !== $this->get_unique_name() ) {
|
||||
/** @var Widget_Common $common_widget */
|
||||
$common_widget = Plugin::$instance->widgets_manager->get_widget_types( 'common' );
|
||||
|
||||
$stack['controls'] = array_merge( $stack['controls'], $common_widget->get_controls() );
|
||||
|
||||
$stack['tabs'] = array_merge( $stack['tabs'], $common_widget->get_tabs_controls() );
|
||||
}
|
||||
|
||||
return $stack;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get widget controls pointer index.
|
||||
*
|
||||
* Retrieve widget pointer index where the next control should be added.
|
||||
*
|
||||
* While using injection point, it will return the injection point index. Otherwise index of the last control of the
|
||||
* current widget itself without the common controls, plus one.
|
||||
*
|
||||
* @since 1.9.2
|
||||
* @access public
|
||||
*
|
||||
* @return int Widget controls pointer index.
|
||||
*/
|
||||
public function get_pointer_index() {
|
||||
$injection_point = $this->get_injection_point();
|
||||
|
||||
if ( null !== $injection_point ) {
|
||||
return $injection_point['index'];
|
||||
}
|
||||
|
||||
return count( $this->get_stack( false )['controls'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Show in panel.
|
||||
*
|
||||
* Whether to show the widget in the panel or not. By default returns true.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
*
|
||||
* @return bool Whether to show the widget in the panel or not.
|
||||
*/
|
||||
public function show_in_panel() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start widget controls section.
|
||||
*
|
||||
* Used to add a new section of controls to the widget. Regular controls and
|
||||
* skin controls.
|
||||
*
|
||||
* Note that when you add new controls to widgets they must be wrapped by
|
||||
* `start_controls_section()` and `end_controls_section()`.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
*
|
||||
* @param string $section_id Section ID.
|
||||
* @param array $args Section arguments Optional.
|
||||
*/
|
||||
public function start_controls_section( $section_id, array $args = [] ) {
|
||||
parent::start_controls_section( $section_id, $args );
|
||||
|
||||
static $is_first_section = true;
|
||||
|
||||
if ( $is_first_section ) {
|
||||
$this->register_skin_control();
|
||||
|
||||
$is_first_section = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the Skin Control if the widget has skins.
|
||||
*
|
||||
* An internal method that is used to add a skin control to the widget.
|
||||
* Added at the top of the controls section.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access private
|
||||
*/
|
||||
private function register_skin_control() {
|
||||
$skins = $this->get_skins();
|
||||
if ( ! empty( $skins ) ) {
|
||||
$skin_options = [];
|
||||
|
||||
if ( $this->_has_template_content ) {
|
||||
$skin_options[''] = __( 'Default', 'elementor' );
|
||||
}
|
||||
|
||||
foreach ( $skins as $skin_id => $skin ) {
|
||||
$skin_options[ $skin_id ] = $skin->get_title();
|
||||
}
|
||||
|
||||
// Get the first item for default value
|
||||
$default_value = array_keys( $skin_options );
|
||||
$default_value = array_shift( $default_value );
|
||||
|
||||
if ( 1 >= count( $skin_options ) ) {
|
||||
$this->add_control(
|
||||
'_skin',
|
||||
[
|
||||
'label' => __( 'Skin', 'elementor' ),
|
||||
'type' => Controls_Manager::HIDDEN,
|
||||
'default' => $default_value,
|
||||
]
|
||||
);
|
||||
} else {
|
||||
$this->add_control(
|
||||
'_skin',
|
||||
[
|
||||
'label' => __( 'Skin', 'elementor' ),
|
||||
'type' => Controls_Manager::SELECT,
|
||||
'default' => $default_value,
|
||||
'options' => $skin_options,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register widget skins.
|
||||
*
|
||||
* This method is activated while initializing the widget base class. It is
|
||||
* used to assign skins to widgets with `add_skin()` method.
|
||||
*
|
||||
* Usage:
|
||||
*
|
||||
* protected function _register_skins() {
|
||||
* $this->add_skin( new Skin_Classic( $this ) );
|
||||
* }
|
||||
*
|
||||
* @since 1.7.12
|
||||
* @access protected
|
||||
*/
|
||||
protected function _register_skins() {}
|
||||
|
||||
/**
|
||||
* Get initial config.
|
||||
*
|
||||
* Retrieve the current widget initial configuration.
|
||||
*
|
||||
* Adds more configuration on top of the controls list, the tabs assigned to
|
||||
* the control, element name, type, icon and more. This method also adds
|
||||
* widget type, keywords and categories.
|
||||
*
|
||||
* @since 2.9.0
|
||||
* @access protected
|
||||
*
|
||||
* @return array The initial widget config.
|
||||
*/
|
||||
protected function get_initial_config() {
|
||||
$config = [
|
||||
'widget_type' => $this->get_name(),
|
||||
'keywords' => $this->get_keywords(),
|
||||
'categories' => $this->get_categories(),
|
||||
'html_wrapper_class' => $this->get_html_wrapper_class(),
|
||||
'show_in_panel' => $this->show_in_panel(),
|
||||
];
|
||||
|
||||
$stack = Plugin::$instance->controls_manager->get_element_stack( $this );
|
||||
|
||||
if ( $stack ) {
|
||||
$config['controls'] = $this->get_stack( false )['controls'];
|
||||
$config['tabs_controls'] = $this->get_tabs_controls();
|
||||
}
|
||||
|
||||
return array_merge( parent::get_initial_config(), $config );
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.3.1
|
||||
* @access protected
|
||||
*/
|
||||
protected function should_print_empty() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Print widget content template.
|
||||
*
|
||||
* Used to generate the widget content template on the editor, using a
|
||||
* Backbone JavaScript template.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access protected
|
||||
*
|
||||
* @param string $template_content Template content.
|
||||
*/
|
||||
protected function print_template_content( $template_content ) {
|
||||
?>
|
||||
<div class="elementor-widget-container">
|
||||
<?php
|
||||
echo $template_content; // XSS ok.
|
||||
?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse text editor.
|
||||
*
|
||||
* Parses the content from rich text editor with shortcodes, oEmbed and
|
||||
* filtered data.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access protected
|
||||
*
|
||||
* @param string $content Text editor content.
|
||||
*
|
||||
* @return string Parsed content.
|
||||
*/
|
||||
protected function parse_text_editor( $content ) {
|
||||
/** This filter is documented in wp-includes/widgets/class-wp-widget-text.php */
|
||||
$content = apply_filters( 'widget_text', $content, $this->get_settings() );
|
||||
|
||||
$content = shortcode_unautop( $content );
|
||||
$content = do_shortcode( $content );
|
||||
$content = wptexturize( $content );
|
||||
|
||||
if ( $GLOBALS['wp_embed'] instanceof \WP_Embed ) {
|
||||
$content = $GLOBALS['wp_embed']->autoembed( $content );
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get HTML wrapper class.
|
||||
*
|
||||
* Retrieve the widget container class. Can be used to override the
|
||||
* container class for specific widgets.
|
||||
*
|
||||
* @since 2.0.9
|
||||
* @access protected
|
||||
*/
|
||||
protected function get_html_wrapper_class() {
|
||||
return 'elementor-widget-' . $this->get_name();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add widget render attributes.
|
||||
*
|
||||
* Used to add attributes to the current widget wrapper HTML tag.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access protected
|
||||
*/
|
||||
protected function _add_render_attributes() {
|
||||
parent::_add_render_attributes();
|
||||
|
||||
$this->add_render_attribute(
|
||||
'_wrapper', 'class', [
|
||||
'elementor-widget',
|
||||
$this->get_html_wrapper_class(),
|
||||
]
|
||||
);
|
||||
|
||||
$settings = $this->get_settings();
|
||||
|
||||
$this->add_render_attribute( '_wrapper', 'data-widget_type', $this->get_name() . '.' . ( ! empty( $settings['_skin'] ) ? $settings['_skin'] : 'default' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add lightbox data to image link.
|
||||
*
|
||||
* Used to add lightbox data attributes to image link HTML.
|
||||
*
|
||||
* @since 2.9.1
|
||||
* @access public
|
||||
*
|
||||
* @param string $link_html Image link HTML.
|
||||
* @param string $id Attachment id.
|
||||
*
|
||||
* @return string Image link HTML with lightbox data attributes.
|
||||
*/
|
||||
public function add_lightbox_data_to_image_link( $link_html, $id ) {
|
||||
$settings = $this->get_settings_for_display();
|
||||
$open_lightbox = isset( $settings['open_lightbox'] ) ? $settings['open_lightbox'] : null;
|
||||
|
||||
if ( Plugin::$instance->editor->is_edit_mode() ) {
|
||||
$this->add_render_attribute( 'link', 'class', 'elementor-clickable', true );
|
||||
}
|
||||
|
||||
$this->add_lightbox_data_attributes( 'link', $id, $open_lightbox, $this->get_id(), true );
|
||||
return preg_replace( '/^<a/', '<a ' . $this->get_render_attribute_string( 'link' ), $link_html );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Light-Box attributes.
|
||||
*
|
||||
* Used to add Light-Box-related data attributes to links that open media files.
|
||||
*
|
||||
* @param array|string $element The link HTML element.
|
||||
* @param int $id The ID of the image
|
||||
* @param string $lightbox_setting_key The setting key that dictates weather to open the image in a lightbox
|
||||
* @param string $group_id Unique ID for a group of lightbox images
|
||||
* @param bool $overwrite Optional. Whether to overwrite existing
|
||||
* attribute. Default is false, not to overwrite.
|
||||
*
|
||||
* @return Widget_Base Current instance of the widget.
|
||||
* @since 2.9.0
|
||||
* @access public
|
||||
*
|
||||
*/
|
||||
public function add_lightbox_data_attributes( $element, $id = null, $lightbox_setting_key = null, $group_id = null, $overwrite = false ) {
|
||||
$kit = Plugin::$instance->kits_manager->get_active_kit();
|
||||
|
||||
$is_global_image_lightbox_enabled = 'yes' === $kit->get_settings( 'global_image_lightbox' );
|
||||
|
||||
if ( 'no' === $lightbox_setting_key ) {
|
||||
if ( $is_global_image_lightbox_enabled ) {
|
||||
$this->add_render_attribute( $element, 'data-elementor-open-lightbox', 'no' );
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
if ( 'yes' !== $lightbox_setting_key && ! $is_global_image_lightbox_enabled ) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$attributes['data-elementor-open-lightbox'] = 'yes';
|
||||
|
||||
if ( $group_id ) {
|
||||
$attributes['data-elementor-lightbox-slideshow'] = $group_id;
|
||||
}
|
||||
|
||||
if ( $id ) {
|
||||
$lightbox_image_attributes = Plugin::$instance->images_manager->get_lightbox_image_attributes( $id );
|
||||
|
||||
if ( isset( $lightbox_image_attributes['title'] ) ) {
|
||||
$attributes['data-elementor-lightbox-title'] = $lightbox_image_attributes['title'];
|
||||
}
|
||||
|
||||
if ( isset( $lightbox_image_attributes['description'] ) ) {
|
||||
$attributes['data-elementor-lightbox-description'] = $lightbox_image_attributes['description'];
|
||||
}
|
||||
}
|
||||
|
||||
$this->add_render_attribute( $element, $attributes, null, $overwrite );
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render widget output on the frontend.
|
||||
*
|
||||
* Used to generate the final HTML displayed on the frontend.
|
||||
*
|
||||
* Note that if skin is selected, it will be rendered by the skin itself,
|
||||
* not the widget.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
*/
|
||||
public function render_content() {
|
||||
/**
|
||||
* Before widget render content.
|
||||
*
|
||||
* Fires before Elementor widget is being rendered.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param Widget_Base $this The current widget.
|
||||
*/
|
||||
do_action( 'elementor/widget/before_render_content', $this );
|
||||
|
||||
ob_start();
|
||||
|
||||
$skin = $this->get_current_skin();
|
||||
if ( $skin ) {
|
||||
$skin->set_parent( $this );
|
||||
$skin->render();
|
||||
} else {
|
||||
$this->render();
|
||||
}
|
||||
|
||||
$widget_content = ob_get_clean();
|
||||
|
||||
if ( empty( $widget_content ) ) {
|
||||
return;
|
||||
}
|
||||
?>
|
||||
<div class="elementor-widget-container">
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Render widget content.
|
||||
*
|
||||
* Filters the widget content before it's rendered.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param string $widget_content The content of the widget.
|
||||
* @param Widget_Base $this The widget.
|
||||
*/
|
||||
$widget_content = apply_filters( 'elementor/widget/render_content', $widget_content, $this );
|
||||
|
||||
echo $widget_content; // XSS ok.
|
||||
?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Render widget plain content.
|
||||
*
|
||||
* Elementor saves the page content in a unique way, but it's not the way
|
||||
* WordPress saves data. This method is used to save generated HTML to the
|
||||
* database as plain content the WordPress way.
|
||||
*
|
||||
* When rendering plain content, it allows other WordPress plugins to
|
||||
* interact with the content - to search, check SEO and other purposes. It
|
||||
* also allows the site to keep working even if Elementor is deactivated.
|
||||
*
|
||||
* Note that if the widget uses shortcodes to display the data, the best
|
||||
* practice is to return the shortcode itself.
|
||||
*
|
||||
* Also note that if the widget don't display any content it should return
|
||||
* an empty string. For example Elementor Pro Form Widget uses this method
|
||||
* to return an empty string because there is no content to return. This way
|
||||
* if Elementor Pro will be deactivated there won't be any form to display.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
*/
|
||||
public function render_plain_content() {
|
||||
$this->render_content();
|
||||
}
|
||||
|
||||
/**
|
||||
* Before widget rendering.
|
||||
*
|
||||
* Used to add stuff before the widget `_wrapper` element.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
*/
|
||||
public function before_render() {
|
||||
?>
|
||||
<div <?php $this->print_render_attribute_string( '_wrapper' ); ?>>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* After widget rendering.
|
||||
*
|
||||
* Used to add stuff after the widget `_wrapper` element.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
*/
|
||||
public function after_render() {
|
||||
?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the element raw data.
|
||||
*
|
||||
* Retrieve the raw element data, including the id, type, settings, child
|
||||
* elements and whether it is an inner element.
|
||||
*
|
||||
* The data with the HTML used always to display the data, but the Elementor
|
||||
* editor uses the raw data without the HTML in order not to render the data
|
||||
* again.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
*
|
||||
* @param bool $with_html_content Optional. Whether to return the data with
|
||||
* HTML content or without. Used for caching.
|
||||
* Default is false, without HTML.
|
||||
*
|
||||
* @return array Element raw data.
|
||||
*/
|
||||
public function get_raw_data( $with_html_content = false ) {
|
||||
$data = parent::get_raw_data( $with_html_content );
|
||||
|
||||
unset( $data['isInner'] );
|
||||
|
||||
$data['widgetType'] = $this->get_data( 'widgetType' );
|
||||
|
||||
if ( $with_html_content ) {
|
||||
ob_start();
|
||||
|
||||
$this->render_content();
|
||||
|
||||
$data['htmlCache'] = ob_get_clean();
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Print widget content.
|
||||
*
|
||||
* Output the widget final HTML on the frontend.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access protected
|
||||
*/
|
||||
protected function _print_content() {
|
||||
$this->render_content();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default data.
|
||||
*
|
||||
* Retrieve the default widget data. Used to reset the data on initialization.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access protected
|
||||
*
|
||||
* @return array Default data.
|
||||
*/
|
||||
protected function get_default_data() {
|
||||
$data = parent::get_default_data();
|
||||
|
||||
$data['widgetType'] = '';
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default child type.
|
||||
*
|
||||
* Retrieve the widget child type based on element data.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access protected
|
||||
*
|
||||
* @param array $element_data Widget ID.
|
||||
*
|
||||
* @return array|false Child type or false if it's not a valid widget.
|
||||
*/
|
||||
protected function _get_default_child_type( array $element_data ) {
|
||||
return Plugin::$instance->elements_manager->get_element_types( 'section' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get repeater setting key.
|
||||
*
|
||||
* Retrieve the unique setting key for the current repeater item. Used to connect the current element in the
|
||||
* repeater to it's settings model and it's control in the panel.
|
||||
*
|
||||
* PHP usage (inside `Widget_Base::render()` method):
|
||||
*
|
||||
* $tabs = $this->get_settings( 'tabs' );
|
||||
* foreach ( $tabs as $index => $item ) {
|
||||
* $tab_title_setting_key = $this->get_repeater_setting_key( 'tab_title', 'tabs', $index );
|
||||
* $this->add_inline_editing_attributes( $tab_title_setting_key, 'none' );
|
||||
* echo '<div ' . $this->get_render_attribute_string( $tab_title_setting_key ) . '>' . $item['tab_title'] . '</div>';
|
||||
* }
|
||||
*
|
||||
* @since 1.8.0
|
||||
* @access protected
|
||||
*
|
||||
* @param string $setting_key The current setting key inside the repeater item (e.g. `tab_title`).
|
||||
* @param string $repeater_key The repeater key containing the array of all the items in the repeater (e.g. `tabs`).
|
||||
* @param int $repeater_item_index The current item index in the repeater array (e.g. `3`).
|
||||
*
|
||||
* @return string The repeater setting key (e.g. `tabs.3.tab_title`).
|
||||
*/
|
||||
protected function get_repeater_setting_key( $setting_key, $repeater_key, $repeater_item_index ) {
|
||||
return implode( '.', [ $repeater_key, $repeater_item_index, $setting_key ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add inline editing attributes.
|
||||
*
|
||||
* Define specific area in the element to be editable inline. The element can have several areas, with this method
|
||||
* you can set the area inside the element that can be edited inline. You can also define the type of toolbar the
|
||||
* user will see, whether it will be a basic toolbar or an advanced one.
|
||||
*
|
||||
* Note: When you use wysiwyg control use the advanced toolbar, with textarea control use the basic toolbar. Text
|
||||
* control should not have toolbar.
|
||||
*
|
||||
* PHP usage (inside `Widget_Base::render()` method):
|
||||
*
|
||||
* $this->add_inline_editing_attributes( 'text', 'advanced' );
|
||||
* echo '<div ' . $this->get_render_attribute_string( 'text' ) . '>' . $this->get_settings( 'text' ) . '</div>';
|
||||
*
|
||||
* @since 1.8.0
|
||||
* @access protected
|
||||
*
|
||||
* @param string $key Element key.
|
||||
* @param string $toolbar Optional. Toolbar type. Accepted values are `advanced`, `basic` or `none`. Default is
|
||||
* `basic`.
|
||||
*/
|
||||
protected function add_inline_editing_attributes( $key, $toolbar = 'basic' ) {
|
||||
if ( ! Plugin::$instance->editor->is_edit_mode() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->add_render_attribute( $key, [
|
||||
'class' => 'elementor-inline-editing',
|
||||
'data-elementor-setting-key' => $key,
|
||||
] );
|
||||
|
||||
if ( 'basic' !== $toolbar ) {
|
||||
$this->add_render_attribute( $key, [
|
||||
'data-elementor-inline-editing-toolbar' => $toolbar,
|
||||
] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add new skin.
|
||||
*
|
||||
* Register new widget skin to allow the user to set custom designs. Must be
|
||||
* called inside the `_register_skins()` method.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
*
|
||||
* @param Skin_Base $skin Skin instance.
|
||||
*/
|
||||
public function add_skin( Skin_Base $skin ) {
|
||||
Plugin::$instance->skins_manager->add_skin( $this, $skin );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get single skin.
|
||||
*
|
||||
* Retrieve a single skin based on skin ID, from all the skin assigned to
|
||||
* the widget. If the skin does not exist or not assigned to the widget,
|
||||
* return false.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
*
|
||||
* @param string $skin_id Skin ID.
|
||||
*
|
||||
* @return string|false Single skin, or false.
|
||||
*/
|
||||
public function get_skin( $skin_id ) {
|
||||
$skins = $this->get_skins();
|
||||
if ( isset( $skins[ $skin_id ] ) ) {
|
||||
return $skins[ $skin_id ];
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current skin ID.
|
||||
*
|
||||
* Retrieve the ID of the current skin.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
*
|
||||
* @return string Current skin.
|
||||
*/
|
||||
public function get_current_skin_id() {
|
||||
return $this->get_settings( '_skin' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current skin.
|
||||
*
|
||||
* Retrieve the current skin, or if non exist return false.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
*
|
||||
* @return Skin_Base|false Current skin or false.
|
||||
*/
|
||||
public function get_current_skin() {
|
||||
return $this->get_skin( $this->get_current_skin_id() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove widget skin.
|
||||
*
|
||||
* Unregister an existing skin and remove it from the widget.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
*
|
||||
* @param string $skin_id Skin ID.
|
||||
*
|
||||
* @return \WP_Error|true Whether the skin was removed successfully from the widget.
|
||||
*/
|
||||
public function remove_skin( $skin_id ) {
|
||||
return Plugin::$instance->skins_manager->remove_skin( $this, $skin_id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get widget skins.
|
||||
*
|
||||
* Retrieve all the skin assigned to the widget.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
*
|
||||
* @return Skin_Base[]
|
||||
*/
|
||||
public function get_skins() {
|
||||
return Plugin::$instance->skins_manager->get_skins( $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $plugin_title Plugin's title
|
||||
* @param string $since Plugin version widget was deprecated
|
||||
* @param string $last Plugin version in which the widget will be removed
|
||||
* @param string $replacement Widget replacement
|
||||
*/
|
||||
protected function deprecated_notice( $plugin_title, $since, $last = '', $replacement = '' ) {
|
||||
$this->start_controls_section( 'Deprecated',
|
||||
[
|
||||
'label' => __( 'Deprecated', 'elementor' ),
|
||||
]
|
||||
);
|
||||
|
||||
$this->add_control(
|
||||
'deprecated_notice',
|
||||
[
|
||||
'type' => Controls_Manager::DEPRECATED_NOTICE,
|
||||
'widget' => $this->get_title(),
|
||||
'since' => $since,
|
||||
'last' => $last,
|
||||
'plugin' => $plugin_title,
|
||||
'replacement' => $replacement,
|
||||
]
|
||||
);
|
||||
|
||||
$this->end_controls_section();
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user