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

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

479 lines 11.3 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 ]
347 );
348
349 $this->add_control(
350 'title_color',
351 [
352 'label' => esc_html__( 'Text Color', 'elementor' ),
353 'type' => Controls_Manager::COLOR,
354 'global' => [
355 'default' => Global_Colors::COLOR_PRIMARY,
356 ],
357 'selectors' => [
358 '{{WRAPPER}} .elementor-heading-title' => 'color: {{VALUE}};',
359 ],
360 ]
361 );
362
363 $this->end_controls_tab();
364
365 $this->start_controls_tab(
366 'title_colors_hover',
367 [
368 'label' => esc_html__( 'Hover', 'elementor' ),
369 ]
370 );
371
372 $this->add_control(
373 'title_hover_color',
374 [
375 'label' => esc_html__( 'Text Color', 'elementor' ),
376 'type' => Controls_Manager::COLOR,
377 'selectors' => [
378 '{{WRAPPER}} .elementor-heading-title:hover' => 'color: {{VALUE}};',
379 ],
380 ]
381 );
382
383 $this->add_control(
384 'title_hover_color_transition_duration',
385 [
386 'label' => esc_html__( 'Transition Duration', 'elementor' ),
387 'type' => Controls_Manager::SLIDER,
388 'size_units' => [ 's', 'ms', 'custom' ],
389 'default' => [
390 'unit' => 's',
391 ],
392 'selectors' => [
393 '{{WRAPPER}} .elementor-heading-title' => 'transition-duration: {{SIZE}}{{UNIT}};',
394 ],
395 ]
396 );
397
398 $this->end_controls_tab();
399
400 $this->end_controls_tabs();
401
402 $this->end_controls_section();
403 }
404
405 /**
406 * Render heading widget output on the frontend.
407 *
408 * Written in PHP and used to generate the final HTML.
409 *
410 * @since 1.0.0
411 * @access protected
412 */
413 protected function render() {
414 $settings = $this->get_settings_for_display();
415
416 if ( '' === $settings['title'] ) {
417 return;
418 }
419
420 $this->add_render_attribute( 'title', 'class', 'elementor-heading-title' );
421
422 if ( ! empty( $settings['size'] ) ) {
423 $this->add_render_attribute( 'title', 'class', 'elementor-size-' . $settings['size'] );
424 } else {
425 $this->add_render_attribute( 'title', 'class', 'elementor-size-default' );
426 }
427
428 $this->add_inline_editing_attributes( 'title' );
429
430 $title = wp_kses_post( $settings['title'] );
431
432 if ( ! empty( $settings['link']['url'] ) ) {
433 $this->add_link_attributes( 'url', $settings['link'] );
434
435 $title = sprintf( '<a %1$s>%2$s</a>', $this->get_render_attribute_string( 'url' ), $title );
436 }
437
438 $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 );
439
440 // PHPCS - the variable $title_html holds safe data.
441 echo $title_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
442 }
443
444 /**
445 * Render heading widget output in the editor.
446 *
447 * Written as a Backbone JavaScript template and used to generate the live preview.
448 *
449 * @since 2.9.0
450 * @access protected
451 */
452 protected function content_template() {
453 ?>
454 <#
455 let title = elementor.helpers.sanitize( settings.title, { ALLOW_DATA_ATTR: false } );
456
457 if ( '' !== settings.link.url ) {
458 title = '<a href="' + elementor.helpers.sanitizeUrl( settings.link.url ) + '">' + title + '</a>';
459 }
460
461 view.addRenderAttribute( 'title', 'class', [ 'elementor-heading-title' ] );
462
463 if ( '' !== settings.size ) {
464 view.addRenderAttribute( 'title', 'class', [ 'elementor-size-' + settings.size ] );
465 } else {
466 view.addRenderAttribute( 'title', 'class', [ 'elementor-size-default' ] );
467 }
468
469 view.addInlineEditingAttributes( 'title' );
470
471 var headerSizeTag = elementor.helpers.validateHTMLTag( settings.header_size ),
472 title_html = '<' + headerSizeTag + ' ' + view.getRenderAttributeString( 'title' ) + '>' + title + '</' + headerSizeTag + '>';
473
474 print( title_html );
475 #>
476 <?php
477 }
478 }
479