PluginProbe
Elementor Website Builder – more than just a page builder / 3.26.4
Elementor Website Builder – more than just a page builder v3.26.4
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 / widgets / heading.php

heading.php in Elementor Website Builder – more than just a page builder 3.26.4, at includes/widgets/heading.php

488 lines 11.4 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 use Elementor\Core\Kits\Documents\Tabs\Global_Colors;
9 use Elementor\Core\Kits\Documents\Tabs\Global_Typography;
10 use Elementor\Modules\ContentSanitizer\Interfaces\Sanitizable;
11 use Elementor\Modules\Promotions\Controls\Promotion_Control;
12 use Elementor\Utils;
13
14 /**
15 * Elementor heading widget.
16 *
17 * Elementor widget that displays an eye-catching headlines.
18 *
19 * @since 1.0.0
20 */
21 class Widget_Heading extends Widget_Base implements Sanitizable {
22
23 /**
24 * Get widget name.
25 *
26 * Retrieve heading widget name.
27 *
28 * @since 1.0.0
29 * @access public
30 *
31 * @return string Widget name.
32 */
33 public function get_name() {
34 return 'heading';
35 }
36
37 /**
38 * Get widget title.
39 *
40 * Retrieve heading widget title.
41 *
42 * @since 1.0.0
43 * @access public
44 *
45 * @return string Widget title.
46 */
47 public function get_title() {
48 return esc_html__( 'Heading', 'elementor' );
49 }
50
51 /**
52 * Get widget icon.
53 *
54 * Retrieve heading widget icon.
55 *
56 * @since 1.0.0
57 * @access public
58 *
59 * @return string Widget icon.
60 */
61 public function get_icon() {
62 return 'eicon-t-letter';
63 }
64
65 /**
66 * Get widget categories.
67 *
68 * Retrieve the list of categories the heading widget belongs to.
69 *
70 * Used to determine where to display the widget in the editor.
71 *
72 * @since 2.0.0
73 * @access public
74 *
75 * @return array Widget categories.
76 */
77 public function get_categories() {
78 return [ 'basic' ];
79 }
80
81 /**
82 * Get widget keywords.
83 *
84 * Retrieve the list of keywords the widget belongs to.
85 *
86 * @since 2.1.0
87 * @access public
88 *
89 * @return array Widget keywords.
90 */
91 public function get_keywords() {
92 return [ 'heading', 'title', 'text' ];
93 }
94
95 protected function is_dynamic_content(): bool {
96 return false;
97 }
98
99 /**
100 * Get style dependencies.
101 *
102 * Retrieve the list of style dependencies the widget requires.
103 *
104 * @since 3.24.0
105 * @access public
106 *
107 * @return array Widget style dependencies.
108 */
109 public function get_style_depends(): array {
110 return [ 'widget-heading' ];
111 }
112
113 public function has_widget_inner_wrapper(): bool {
114 return ! Plugin::$instance->experiments->is_feature_active( 'e_optimized_markup' );
115 }
116
117 /**
118 * Remove data attributes from the html.
119 *
120 * @param string $content Heading title
121 * @return string
122 */
123 public function sanitize( $content ): string {
124 $allowed_tags = wp_kses_allowed_html( 'post' );
125 $allowed_tags_for_heading = [];
126 $non_allowed_tags = [ 'img' ];
127
128 foreach ( $allowed_tags as $tag => $attributes ) {
129 if ( in_array( $tag, $non_allowed_tags, true ) ) {
130 continue;
131 }
132
133 $filtered_attributes = array_filter( $attributes, function( $attribute ) {
134 return ! substr( $attribute, 0, 5 ) === 'data-';
135 }, ARRAY_FILTER_USE_KEY );
136
137 $allowed_tags_for_heading[ $tag ] = $filtered_attributes;
138 }
139
140 return wp_kses( $content, $allowed_tags_for_heading );
141 }
142
143 /**
144 * Register heading widget controls.
145 *
146 * Adds different input fields to allow the user to change and customize the widget settings.
147 *
148 * @since 3.1.0
149 * @access protected
150 */
151 protected function register_controls() {
152 $this->start_controls_section(
153 'section_title',
154 [
155 'label' => esc_html__( 'Heading', 'elementor' ),
156 ]
157 );
158
159 $this->add_control(
160 'title',
161 [
162 'label' => esc_html__( 'Title', 'elementor' ),
163 'type' => Controls_Manager::TEXTAREA,
164 'ai' => [
165 'type' => 'text',
166 ],
167 'dynamic' => [
168 'active' => true,
169 ],
170 'placeholder' => esc_html__( 'Enter your title', 'elementor' ),
171 'default' => esc_html__( 'Add Your Heading Text Here', 'elementor' ),
172 ]
173 );
174
175 $this->add_control(
176 'link',
177 [
178 'label' => esc_html__( 'Link', 'elementor' ),
179 'type' => Controls_Manager::URL,
180 'dynamic' => [
181 'active' => true,
182 ],
183 'default' => [
184 'url' => '',
185 ],
186 ]
187 );
188
189 $this->add_control(
190 'size',
191 [
192 'label' => esc_html__( 'Size', 'elementor' ),
193 'type' => Controls_Manager::SELECT,
194 'options' => [
195 'default' => esc_html__( 'Default', 'elementor' ),
196 'small' => esc_html__( 'Small', 'elementor' ),
197 'medium' => esc_html__( 'Medium', 'elementor' ),
198 'large' => esc_html__( 'Large', 'elementor' ),
199 'xl' => esc_html__( 'XL', 'elementor' ),
200 'xxl' => esc_html__( 'XXL', 'elementor' ),
201 ],
202 'default' => 'default',
203 'condition' => [
204 'size!' => 'default', // a workaround to hide the control, unless it's in use (not default).
205 ],
206 ]
207 );
208
209 $this->add_control(
210 'header_size',
211 [
212 'label' => esc_html__( 'HTML Tag', 'elementor' ),
213 'type' => Controls_Manager::SELECT,
214 'options' => [
215 'h1' => 'H1',
216 'h2' => 'H2',
217 'h3' => 'H3',
218 'h4' => 'H4',
219 'h5' => 'H5',
220 'h6' => 'H6',
221 'div' => 'div',
222 'span' => 'span',
223 'p' => 'p',
224 ],
225 'default' => 'h2',
226 ]
227 );
228
229 if ( ! Utils::has_pro() ) {
230 $this->add_control(
231 Utils::ANIMATED_HEADLINE . '_promotion',
232 [
233 'label' => esc_html__( 'Animated Headline widget', 'elementor' ),
234 'type' => Promotion_Control::TYPE,
235 ]
236 );
237 }
238
239 $this->end_controls_section();
240
241 $this->start_controls_section(
242 'section_title_style',
243 [
244 'label' => esc_html__( 'Heading', 'elementor' ),
245 'tab' => Controls_Manager::TAB_STYLE,
246 ]
247 );
248
249 $this->add_responsive_control(
250 'align',
251 [
252 'label' => esc_html__( 'Alignment', 'elementor' ),
253 'type' => Controls_Manager::CHOOSE,
254 'options' => [
255 'left' => [
256 'title' => esc_html__( 'Left', 'elementor' ),
257 'icon' => 'eicon-text-align-left',
258 ],
259 'center' => [
260 'title' => esc_html__( 'Center', 'elementor' ),
261 'icon' => 'eicon-text-align-center',
262 ],
263 'right' => [
264 'title' => esc_html__( 'Right', 'elementor' ),
265 'icon' => 'eicon-text-align-right',
266 ],
267 'justify' => [
268 'title' => esc_html__( 'Justified', 'elementor' ),
269 'icon' => 'eicon-text-align-justify',
270 ],
271 ],
272 'default' => '',
273 'selectors' => [
274 '{{WRAPPER}}' => 'text-align: {{VALUE}};',
275 ],
276 'separator' => 'after',
277 ]
278 );
279
280 $this->add_group_control(
281 Group_Control_Typography::get_type(),
282 [
283 'name' => 'typography',
284 'global' => [
285 'default' => Global_Typography::TYPOGRAPHY_PRIMARY,
286 ],
287 'selector' => '{{WRAPPER}} .elementor-heading-title',
288 ]
289 );
290
291 $this->add_group_control(
292 Group_Control_Text_Stroke::get_type(),
293 [
294 'name' => 'text_stroke',
295 'selector' => '{{WRAPPER}} .elementor-heading-title',
296 ]
297 );
298
299 $this->add_group_control(
300 Group_Control_Text_Shadow::get_type(),
301 [
302 'name' => 'text_shadow',
303 'selector' => '{{WRAPPER}} .elementor-heading-title',
304 ]
305 );
306
307 $this->add_control(
308 'blend_mode',
309 [
310 'label' => esc_html__( 'Blend Mode', 'elementor' ),
311 'type' => Controls_Manager::SELECT,
312 'options' => [
313 '' => esc_html__( 'Normal', 'elementor' ),
314 'multiply' => esc_html__( 'Multiply', 'elementor' ),
315 'screen' => esc_html__( 'Screen', 'elementor' ),
316 'overlay' => esc_html__( 'Overlay', 'elementor' ),
317 'darken' => esc_html__( 'Darken', 'elementor' ),
318 'lighten' => esc_html__( 'Lighten', 'elementor' ),
319 'color-dodge' => esc_html__( 'Color Dodge', 'elementor' ),
320 'saturation' => esc_html__( 'Saturation', 'elementor' ),
321 'color' => esc_html__( 'Color', 'elementor' ),
322 'difference' => esc_html__( 'Difference', 'elementor' ),
323 'exclusion' => esc_html__( 'Exclusion', 'elementor' ),
324 'hue' => esc_html__( 'Hue', 'elementor' ),
325 'luminosity' => esc_html__( 'Luminosity', 'elementor' ),
326 ],
327 'selectors' => [
328 '{{WRAPPER}} .elementor-heading-title' => 'mix-blend-mode: {{VALUE}}',
329 ],
330 ]
331 );
332
333 $this->add_control(
334 'separator',
335 [
336 'type' => Controls_Manager::DIVIDER,
337 ]
338 );
339
340 $this->start_controls_tabs( 'title_colors' );
341
342 $this->start_controls_tab(
343 'title_colors_normal',
344 [
345 'label' => esc_html__( 'Normal', 'elementor' ),
346 'condition' => [
347 'link[url]!' => '',
348 ],
349 ]
350 );
351
352 $this->add_control(
353 'title_color',
354 [
355 'label' => esc_html__( 'Text Color', 'elementor' ),
356 'type' => Controls_Manager::COLOR,
357 'global' => [
358 'default' => Global_Colors::COLOR_PRIMARY,
359 ],
360 'selectors' => [
361 '{{WRAPPER}} .elementor-heading-title' => 'color: {{VALUE}};',
362 ],
363 ]
364 );
365
366 $this->end_controls_tab();
367
368 $this->start_controls_tab(
369 'title_colors_hover',
370 [
371 'label' => esc_html__( 'Hover', 'elementor' ),
372 'condition' => [
373 'link[url]!' => '',
374 ],
375 ]
376 );
377
378 $this->add_control(
379 'title_hover_color',
380 [
381 'label' => esc_html__( 'Text Color', 'elementor' ),
382 'type' => Controls_Manager::COLOR,
383 'selectors' => [
384 '{{WRAPPER}} .elementor-heading-title:hover' => 'color: {{VALUE}};',
385 ],
386 'condition' => [
387 'link[url]!' => '',
388 ],
389 ]
390 );
391
392 $this->add_control(
393 'title_hover_color_transition_duration',
394 [
395 'label' => esc_html__( 'Transition Duration', 'elementor' ),
396 'type' => Controls_Manager::SLIDER,
397 'size_units' => [ 's', 'ms', 'custom' ],
398 'default' => [
399 'unit' => 's',
400 ],
401 'selectors' => [
402 '{{WRAPPER}} .elementor-heading-title' => 'transition-duration: {{SIZE}}{{UNIT}};',
403 ],
404 ]
405 );
406
407 $this->end_controls_tab();
408
409 $this->end_controls_tabs();
410
411 $this->end_controls_section();
412 }
413
414 /**
415 * Render heading widget output on the frontend.
416 *
417 * Written in PHP and used to generate the final HTML.
418 *
419 * @since 1.0.0
420 * @access protected
421 */
422 protected function render() {
423 $settings = $this->get_settings_for_display();
424
425 if ( '' === $settings['title'] ) {
426 return;
427 }
428
429 $this->add_render_attribute( 'title', 'class', 'elementor-heading-title' );
430
431 if ( ! empty( $settings['size'] ) ) {
432 $this->add_render_attribute( 'title', 'class', 'elementor-size-' . $settings['size'] );
433 } else {
434 $this->add_render_attribute( 'title', 'class', 'elementor-size-default' );
435 }
436
437 $this->add_inline_editing_attributes( 'title' );
438
439 $title = wp_kses_post( $settings['title'] );
440
441 if ( ! empty( $settings['link']['url'] ) ) {
442 $this->add_link_attributes( 'url', $settings['link'] );
443
444 $title = sprintf( '<a %1$s>%2$s</a>', $this->get_render_attribute_string( 'url' ), $title );
445 }
446
447 $title_html = sprintf( '<%1$s %2$s>%3$s</%1$s>', Utils::validate_html_tag( $settings['header_size'] ), $this->get_render_attribute_string( 'title' ), $title );
448
449 // PHPCS - the variable $title_html holds safe data.
450 echo $title_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
451 }
452
453 /**
454 * Render heading widget output in the editor.
455 *
456 * Written as a Backbone JavaScript template and used to generate the live preview.
457 *
458 * @since 2.9.0
459 * @access protected
460 */
461 protected function content_template() {
462 ?>
463 <#
464 let title = elementor.helpers.sanitize( settings.title, { ALLOW_DATA_ATTR: false } );
465
466 if ( '' !== settings.link.url ) {
467 title = '<a href="' + elementor.helpers.sanitizeUrl( settings.link.url ) + '">' + title + '</a>';
468 }
469
470 view.addRenderAttribute( 'title', 'class', [ 'elementor-heading-title' ] );
471
472 if ( '' !== settings.size ) {
473 view.addRenderAttribute( 'title', 'class', [ 'elementor-size-' + settings.size ] );
474 } else {
475 view.addRenderAttribute( 'title', 'class', [ 'elementor-size-default' ] );
476 }
477
478 view.addInlineEditingAttributes( 'title' );
479
480 var headerSizeTag = elementor.helpers.validateHTMLTag( settings.header_size ),
481 title_html = '<' + headerSizeTag + ' ' + view.getRenderAttributeString( 'title' ) + '>' + title + '</' + headerSizeTag + '>';
482
483 print( title_html );
484 #>
485 <?php
486 }
487 }
488