| 1 |
<?php |
| 2 |
namespace Elementor; |
| 3 |
|
| 4 |
if ( ! defined( 'ABSPATH' ) ) { |
| 5 |
exit; // Exit if accessed directly. |
| 6 |
} |
| 7 |
|
| 8 |
/** |
| 9 |
* Elementor skin base. |
| 10 |
* |
| 11 |
* An abstract class to register new skins for Elementor widgets. Skins allows |
| 12 |
* you to add new templates, set custom controls and more. |
| 13 |
* |
| 14 |
* To register new skins for your widget use the `add_skin()` method inside the |
| 15 |
* widget's `register_skins()` method. |
| 16 |
* |
| 17 |
* @since 1.0.0 |
| 18 |
* @abstract |
| 19 |
*/ |
| 20 |
abstract class Skin_Base extends Sub_Controls_Stack { |
| 21 |
|
| 22 |
/** |
| 23 |
* Parent widget. |
| 24 |
* |
| 25 |
* Holds the parent widget of the skin. Default value is null, no parent widget. |
| 26 |
* |
| 27 |
* @access protected |
| 28 |
* |
| 29 |
* @var Widget_Base|null |
| 30 |
*/ |
| 31 |
protected $parent = null; |
| 32 |
|
| 33 |
/** |
| 34 |
* Skin base constructor. |
| 35 |
* |
| 36 |
* Initializing the skin base class by setting parent widget and registering |
| 37 |
* controls actions. |
| 38 |
* |
| 39 |
* @since 1.0.0 |
| 40 |
* @access public |
| 41 |
* @param Widget_Base $element_parent |
| 42 |
*/ |
| 43 |
public function __construct( Widget_Base $element_parent ) { |
| 44 |
parent::__construct( $element_parent ); |
| 45 |
|
| 46 |
$this->_register_controls_actions(); |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Render skin. |
| 51 |
* |
| 52 |
* Generates the final HTML on the frontend. |
| 53 |
* |
| 54 |
* @since 1.0.0 |
| 55 |
* @access public |
| 56 |
* @abstract |
| 57 |
*/ |
| 58 |
abstract public function render(); |
| 59 |
|
| 60 |
/** |
| 61 |
* Render element in static mode. |
| 62 |
* |
| 63 |
* If not inherent will call the base render. |
| 64 |
*/ |
| 65 |
public function render_static() { |
| 66 |
$this->render(); |
| 67 |
} |
| 68 |
|
| 69 |
/** |
| 70 |
* Determine the render logic. |
| 71 |
*/ |
| 72 |
public function render_by_mode() { |
| 73 |
if ( Plugin::$instance->frontend->is_static_render_mode() ) { |
| 74 |
$this->render_static(); |
| 75 |
|
| 76 |
return; |
| 77 |
} |
| 78 |
|
| 79 |
$this->render(); |
| 80 |
} |
| 81 |
|
| 82 |
/** |
| 83 |
* Register skin controls actions. |
| 84 |
* |
| 85 |
* Run on init and used to register new skins to be injected to the widget. |
| 86 |
* This method is used to register new actions that specify the location of |
| 87 |
* the skin in the widget. |
| 88 |
* |
| 89 |
* Example usage: |
| 90 |
* `add_action( 'elementor/element/{widget_id}/{section_id}/before_section_end', [ $this, 'register_controls' ] );` |
| 91 |
* |
| 92 |
* @since 1.0.0 |
| 93 |
* @access protected |
| 94 |
*/ |
| 95 |
protected function _register_controls_actions() {} |
| 96 |
|
| 97 |
/** |
| 98 |
* Get skin control ID. |
| 99 |
* |
| 100 |
* Retrieve the skin control ID. Note that skin controls have special prefix |
| 101 |
* to distinguish them from regular controls, and from controls in other |
| 102 |
* skins. |
| 103 |
* |
| 104 |
* @since 1.0.0 |
| 105 |
* @access protected |
| 106 |
* |
| 107 |
* @param string $control_base_id Control base ID. |
| 108 |
* |
| 109 |
* @return string Control ID. |
| 110 |
*/ |
| 111 |
protected function get_control_id( $control_base_id ) { |
| 112 |
$skin_id = str_replace( '-', '_', $this->get_id() ); |
| 113 |
return $skin_id . '_' . $control_base_id; |
| 114 |
} |
| 115 |
|
| 116 |
/** |
| 117 |
* Get skin settings. |
| 118 |
* |
| 119 |
* Retrieve all the skin settings or, when requested, a specific setting. |
| 120 |
* |
| 121 |
* @since 1.0.0 |
| 122 |
* @TODO: rename to get_setting() and create backward compatibility. |
| 123 |
* |
| 124 |
* @access public |
| 125 |
* |
| 126 |
* @param string $control_base_id Control base ID. |
| 127 |
* |
| 128 |
* @return mixed |
| 129 |
*/ |
| 130 |
public function get_instance_value( $control_base_id ) { |
| 131 |
$control_id = $this->get_control_id( $control_base_id ); |
| 132 |
return $this->parent->get_settings( $control_id ); |
| 133 |
} |
| 134 |
|
| 135 |
/** |
| 136 |
* Start skin controls section. |
| 137 |
* |
| 138 |
* Used to add a new section of controls to the skin. |
| 139 |
* |
| 140 |
* @since 1.3.0 |
| 141 |
* @access public |
| 142 |
* |
| 143 |
* @param string $id Section ID. |
| 144 |
* @param array $args Section arguments. |
| 145 |
*/ |
| 146 |
public function start_controls_section( $id, $args = [] ) { |
| 147 |
$args['condition']['_skin'] = $this->get_id(); |
| 148 |
parent::start_controls_section( $id, $args ); |
| 149 |
} |
| 150 |
|
| 151 |
/** |
| 152 |
* Add new skin control. |
| 153 |
* |
| 154 |
* Register a single control to the allow the user to set/update skin data. |
| 155 |
* |
| 156 |
* @param string $id Control ID. |
| 157 |
* @param array $args Control arguments. |
| 158 |
* @param array $options |
| 159 |
* |
| 160 |
* @return bool True if skin added, False otherwise. |
| 161 |
|
| 162 |
* @since 3.0.0 New `$options` parameter added. |
| 163 |
* @access public |
| 164 |
*/ |
| 165 |
public function add_control( $id, $args = [], $options = [] ) { |
| 166 |
$args['condition']['_skin'] = $this->get_id(); |
| 167 |
return parent::add_control( $id, $args, $options ); |
| 168 |
} |
| 169 |
|
| 170 |
/** |
| 171 |
* Update skin control. |
| 172 |
* |
| 173 |
* Change the value of an existing skin control. |
| 174 |
* |
| 175 |
* @since 1.3.0 |
| 176 |
* @since 1.8.1 New `$options` parameter added. |
| 177 |
* |
| 178 |
* @access public |
| 179 |
* |
| 180 |
* @param string $id Control ID. |
| 181 |
* @param array $args Control arguments. Only the new fields you want to update. |
| 182 |
* @param array $options Optional. Some additional options. |
| 183 |
*/ |
| 184 |
public function update_control( $id, $args, array $options = [] ) { |
| 185 |
$args['condition']['_skin'] = $this->get_id(); |
| 186 |
parent::update_control( $id, $args, $options ); |
| 187 |
} |
| 188 |
|
| 189 |
/** |
| 190 |
* Add new responsive skin control. |
| 191 |
* |
| 192 |
* Register a set of controls to allow editing based on user screen size. |
| 193 |
* |
| 194 |
* @param string $id Responsive control ID. |
| 195 |
* @param array $args Responsive control arguments. |
| 196 |
* @param array $options |
| 197 |
* |
| 198 |
* @since 1.0.5 |
| 199 |
* @access public |
| 200 |
*/ |
| 201 |
public function add_responsive_control( $id, $args, $options = [] ) { |
| 202 |
$args['condition']['_skin'] = $this->get_id(); |
| 203 |
parent::add_responsive_control( $id, $args ); |
| 204 |
} |
| 205 |
|
| 206 |
/** |
| 207 |
* Start skin controls tab. |
| 208 |
* |
| 209 |
* Used to add a new tab inside a group of tabs. |
| 210 |
* |
| 211 |
* @since 1.5.0 |
| 212 |
* @access public |
| 213 |
* |
| 214 |
* @param string $id Control ID. |
| 215 |
* @param array $args Control arguments. |
| 216 |
*/ |
| 217 |
public function start_controls_tab( $id, $args ) { |
| 218 |
$args['condition']['_skin'] = $this->get_id(); |
| 219 |
parent::start_controls_tab( $id, $args ); |
| 220 |
} |
| 221 |
|
| 222 |
/** |
| 223 |
* Start skin controls tabs. |
| 224 |
* |
| 225 |
* Used to add a new set of tabs inside a section. |
| 226 |
* |
| 227 |
* @since 1.5.0 |
| 228 |
* @access public |
| 229 |
* |
| 230 |
* @param string $id Control ID. |
| 231 |
*/ |
| 232 |
public function start_controls_tabs( $id ) { |
| 233 |
$args['condition']['_skin'] = $this->get_id(); |
| 234 |
parent::start_controls_tabs( $id ); |
| 235 |
} |
| 236 |
|
| 237 |
/** |
| 238 |
* Add new group control. |
| 239 |
* |
| 240 |
* Register a set of related controls grouped together as a single unified |
| 241 |
* control. |
| 242 |
* |
| 243 |
* @param string $group_name Group control name. |
| 244 |
* @param array $args Group control arguments. Default is an empty array. |
| 245 |
* @param array $options |
| 246 |
* |
| 247 |
* @since 1.0.0 |
| 248 |
* @access public |
| 249 |
*/ |
| 250 |
final public function add_group_control( $group_name, $args = [], $options = [] ) { |
| 251 |
$args['condition']['_skin'] = $this->get_id(); |
| 252 |
parent::add_group_control( $group_name, $args ); |
| 253 |
} |
| 254 |
|
| 255 |
/** |
| 256 |
* Set parent widget. |
| 257 |
* |
| 258 |
* Used to define the parent widget of the skin. |
| 259 |
* |
| 260 |
* @since 1.0.0 |
| 261 |
* @access public |
| 262 |
* |
| 263 |
* @param Widget_Base $element_parent Parent widget. |
| 264 |
*/ |
| 265 |
public function set_parent( $element_parent ) { |
| 266 |
$this->parent = $element_parent; |
| 267 |
} |
| 268 |
} |
| 269 |
|