PluginProbe
Elementor Website Builder – more than just a page builder / 3.16.3
Elementor Website Builder – more than just a page builder v3.16.3
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / includes / base / skin-base.php

skin-base.php in Elementor Website Builder – more than just a page builder 3.16.3, at includes/base/skin-base.php

272 lines 6.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 $parent
42 */
43 public function __construct( Widget_Base $parent ) {
44 parent::__construct( $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 */
166 public function add_control( $id, $args = [], $options = [] ) {
167 $args['condition']['_skin'] = $this->get_id();
168 return parent::add_control( $id, $args, $options );
169 }
170
171 /**
172 * Update skin control.
173 *
174 * Change the value of an existing skin control.
175 *
176 * @since 1.3.0
177 * @since 1.8.1 New `$options` parameter added.
178 *
179 * @access public
180 *
181 * @param string $id Control ID.
182 * @param array $args Control arguments. Only the new fields you want to update.
183 * @param array $options Optional. Some additional options.
184 */
185 public function update_control( $id, $args, array $options = [] ) {
186 $args['condition']['_skin'] = $this->get_id();
187 parent::update_control( $id, $args, $options );
188 }
189
190 /**
191 * Add new responsive skin control.
192 *
193 * Register a set of controls to allow editing based on user screen size.
194 *
195 * @param string $id Responsive control ID.
196 * @param array $args Responsive control arguments.
197 * @param array $options
198 *
199 * @since 1.0.5
200 * @access public
201 *
202 */
203 public function add_responsive_control( $id, $args, $options = [] ) {
204 $args['condition']['_skin'] = $this->get_id();
205 parent::add_responsive_control( $id, $args );
206 }
207
208 /**
209 * Start skin controls tab.
210 *
211 * Used to add a new tab inside a group of tabs.
212 *
213 * @since 1.5.0
214 * @access public
215 *
216 * @param string $id Control ID.
217 * @param array $args Control arguments.
218 */
219 public function start_controls_tab( $id, $args ) {
220 $args['condition']['_skin'] = $this->get_id();
221 parent::start_controls_tab( $id, $args );
222 }
223
224 /**
225 * Start skin controls tabs.
226 *
227 * Used to add a new set of tabs inside a section.
228 *
229 * @since 1.5.0
230 * @access public
231 *
232 * @param string $id Control ID.
233 */
234 public function start_controls_tabs( $id ) {
235 $args['condition']['_skin'] = $this->get_id();
236 parent::start_controls_tabs( $id );
237 }
238
239 /**
240 * Add new group control.
241 *
242 * Register a set of related controls grouped together as a single unified
243 * control.
244 *
245 * @param string $group_name Group control name.
246 * @param array $args Group control arguments. Default is an empty array.
247 * @param array $options
248 *
249 * @since 1.0.0
250 * @access public
251 *
252 */
253 final public function add_group_control( $group_name, $args = [], $options = [] ) {
254 $args['condition']['_skin'] = $this->get_id();
255 parent::add_group_control( $group_name, $args );
256 }
257
258 /**
259 * Set parent widget.
260 *
261 * Used to define the parent widget of the skin.
262 *
263 * @since 1.0.0
264 * @access public
265 *
266 * @param Widget_Base $parent Parent widget.
267 */
268 public function set_parent( $parent ) {
269 $this->parent = $parent;
270 }
271 }
272