| 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 |
|
| 11 |
/** |
| 12 |
* Elementor heading widget. |
| 13 |
* |
| 14 |
* Elementor widget that displays an eye-catching headlines. |
| 15 |
* |
| 16 |
* @since 1.0.0 |
| 17 |
*/ |
| 18 |
class Widget_Heading extends Widget_Base { |
| 19 |
|
| 20 |
/** |
| 21 |
* Get widget name. |
| 22 |
* |
| 23 |
* Retrieve heading widget name. |
| 24 |
* |
| 25 |
* @since 1.0.0 |
| 26 |
* @access public |
| 27 |
* |
| 28 |
* @return string Widget name. |
| 29 |
*/ |
| 30 |
public function get_name() { |
| 31 |
return 'heading'; |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* Get widget title. |
| 36 |
* |
| 37 |
* Retrieve heading widget title. |
| 38 |
* |
| 39 |
* @since 1.0.0 |
| 40 |
* @access public |
| 41 |
* |
| 42 |
* @return string Widget title. |
| 43 |
*/ |
| 44 |
public function get_title() { |
| 45 |
return esc_html__( 'Heading', 'elementor' ); |
| 46 |
} |
| 47 |
|
| 48 |
/** |
| 49 |
* Get widget icon. |
| 50 |
* |
| 51 |
* Retrieve heading widget icon. |
| 52 |
* |
| 53 |
* @since 1.0.0 |
| 54 |
* @access public |
| 55 |
* |
| 56 |
* @return string Widget icon. |
| 57 |
*/ |
| 58 |
public function get_icon() { |
| 59 |
return 'eicon-t-letter'; |
| 60 |
} |
| 61 |
|
| 62 |
/** |
| 63 |
* Get widget categories. |
| 64 |
* |
| 65 |
* Retrieve the list of categories the heading widget belongs to. |
| 66 |
* |
| 67 |
* Used to determine where to display the widget in the editor. |
| 68 |
* |
| 69 |
* @since 2.0.0 |
| 70 |
* @access public |
| 71 |
* |
| 72 |
* @return array Widget categories. |
| 73 |
*/ |
| 74 |
public function get_categories() { |
| 75 |
return [ 'basic' ]; |
| 76 |
} |
| 77 |
|
| 78 |
/** |
| 79 |
* Get widget keywords. |
| 80 |
* |
| 81 |
* Retrieve the list of keywords the widget belongs to. |
| 82 |
* |
| 83 |
* @since 2.1.0 |
| 84 |
* @access public |
| 85 |
* |
| 86 |
* @return array Widget keywords. |
| 87 |
*/ |
| 88 |
public function get_keywords() { |
| 89 |
return [ 'heading', 'title', 'text' ]; |
| 90 |
} |
| 91 |
|
| 92 |
/** |
| 93 |
* Register heading widget controls. |
| 94 |
* |
| 95 |
* Adds different input fields to allow the user to change and customize the widget settings. |
| 96 |
* |
| 97 |
* @since 3.1.0 |
| 98 |
* @access protected |
| 99 |
*/ |
| 100 |
protected function register_controls() { |
| 101 |
$this->start_controls_section( |
| 102 |
'section_title', |
| 103 |
[ |
| 104 |
'label' => esc_html__( 'Title', 'elementor' ), |
| 105 |
] |
| 106 |
); |
| 107 |
|
| 108 |
$this->add_control( |
| 109 |
'title', |
| 110 |
[ |
| 111 |
'label' => esc_html__( 'Title', 'elementor' ), |
| 112 |
'type' => Controls_Manager::TEXTAREA, |
| 113 |
'dynamic' => [ |
| 114 |
'active' => true, |
| 115 |
], |
| 116 |
'placeholder' => esc_html__( 'Enter your title', 'elementor' ), |
| 117 |
'default' => esc_html__( 'Add Your Heading Text Here', 'elementor' ), |
| 118 |
] |
| 119 |
); |
| 120 |
|
| 121 |
$this->add_control( |
| 122 |
'link', |
| 123 |
[ |
| 124 |
'label' => esc_html__( 'Link', 'elementor' ), |
| 125 |
'type' => Controls_Manager::URL, |
| 126 |
'dynamic' => [ |
| 127 |
'active' => true, |
| 128 |
], |
| 129 |
'default' => [ |
| 130 |
'url' => '', |
| 131 |
], |
| 132 |
'separator' => 'before', |
| 133 |
] |
| 134 |
); |
| 135 |
|
| 136 |
$this->add_control( |
| 137 |
'size', |
| 138 |
[ |
| 139 |
'label' => esc_html__( 'Size', 'elementor' ), |
| 140 |
'type' => Controls_Manager::SELECT, |
| 141 |
'default' => 'default', |
| 142 |
'options' => [ |
| 143 |
'default' => esc_html__( 'Default', 'elementor' ), |
| 144 |
'small' => esc_html__( 'Small', 'elementor' ), |
| 145 |
'medium' => esc_html__( 'Medium', 'elementor' ), |
| 146 |
'large' => esc_html__( 'Large', 'elementor' ), |
| 147 |
'xl' => esc_html__( 'XL', 'elementor' ), |
| 148 |
'xxl' => esc_html__( 'XXL', 'elementor' ), |
| 149 |
], |
| 150 |
] |
| 151 |
); |
| 152 |
|
| 153 |
$this->add_control( |
| 154 |
'header_size', |
| 155 |
[ |
| 156 |
'label' => esc_html__( 'HTML Tag', 'elementor' ), |
| 157 |
'type' => Controls_Manager::SELECT, |
| 158 |
'options' => [ |
| 159 |
'h1' => 'H1', |
| 160 |
'h2' => 'H2', |
| 161 |
'h3' => 'H3', |
| 162 |
'h4' => 'H4', |
| 163 |
'h5' => 'H5', |
| 164 |
'h6' => 'H6', |
| 165 |
'div' => 'div', |
| 166 |
'span' => 'span', |
| 167 |
'p' => 'p', |
| 168 |
], |
| 169 |
'default' => 'h2', |
| 170 |
] |
| 171 |
); |
| 172 |
|
| 173 |
$this->add_responsive_control( |
| 174 |
'align', |
| 175 |
[ |
| 176 |
'label' => esc_html__( 'Alignment', 'elementor' ), |
| 177 |
'type' => Controls_Manager::CHOOSE, |
| 178 |
'options' => [ |
| 179 |
'left' => [ |
| 180 |
'title' => esc_html__( 'Left', 'elementor' ), |
| 181 |
'icon' => 'eicon-text-align-left', |
| 182 |
], |
| 183 |
'center' => [ |
| 184 |
'title' => esc_html__( 'Center', 'elementor' ), |
| 185 |
'icon' => 'eicon-text-align-center', |
| 186 |
], |
| 187 |
'right' => [ |
| 188 |
'title' => esc_html__( 'Right', 'elementor' ), |
| 189 |
'icon' => 'eicon-text-align-right', |
| 190 |
], |
| 191 |
'justify' => [ |
| 192 |
'title' => esc_html__( 'Justified', 'elementor' ), |
| 193 |
'icon' => 'eicon-text-align-justify', |
| 194 |
], |
| 195 |
], |
| 196 |
'default' => '', |
| 197 |
'selectors' => [ |
| 198 |
'{{WRAPPER}}' => 'text-align: {{VALUE}};', |
| 199 |
], |
| 200 |
] |
| 201 |
); |
| 202 |
|
| 203 |
$this->add_control( |
| 204 |
'view', |
| 205 |
[ |
| 206 |
'label' => esc_html__( 'View', 'elementor' ), |
| 207 |
'type' => Controls_Manager::HIDDEN, |
| 208 |
'default' => 'traditional', |
| 209 |
] |
| 210 |
); |
| 211 |
|
| 212 |
$this->end_controls_section(); |
| 213 |
|
| 214 |
$this->start_controls_section( |
| 215 |
'section_title_style', |
| 216 |
[ |
| 217 |
'label' => esc_html__( 'Title', 'elementor' ), |
| 218 |
'tab' => Controls_Manager::TAB_STYLE, |
| 219 |
] |
| 220 |
); |
| 221 |
|
| 222 |
$this->add_control( |
| 223 |
'title_color', |
| 224 |
[ |
| 225 |
'label' => esc_html__( 'Text Color', 'elementor' ), |
| 226 |
'type' => Controls_Manager::COLOR, |
| 227 |
'global' => [ |
| 228 |
'default' => Global_Colors::COLOR_PRIMARY, |
| 229 |
], |
| 230 |
'selectors' => [ |
| 231 |
'{{WRAPPER}} .elementor-heading-title' => 'color: {{VALUE}};', |
| 232 |
], |
| 233 |
] |
| 234 |
); |
| 235 |
|
| 236 |
$this->add_group_control( |
| 237 |
Group_Control_Typography::get_type(), |
| 238 |
[ |
| 239 |
'name' => 'typography', |
| 240 |
'global' => [ |
| 241 |
'default' => Global_Typography::TYPOGRAPHY_PRIMARY, |
| 242 |
], |
| 243 |
'selector' => '{{WRAPPER}} .elementor-heading-title', |
| 244 |
] |
| 245 |
); |
| 246 |
|
| 247 |
$this->add_group_control( |
| 248 |
Group_Control_Text_Shadow::get_type(), |
| 249 |
[ |
| 250 |
'name' => 'text_shadow', |
| 251 |
'selector' => '{{WRAPPER}} .elementor-heading-title', |
| 252 |
] |
| 253 |
); |
| 254 |
|
| 255 |
$this->add_control( |
| 256 |
'blend_mode', |
| 257 |
[ |
| 258 |
'label' => esc_html__( 'Blend Mode', 'elementor' ), |
| 259 |
'type' => Controls_Manager::SELECT, |
| 260 |
'options' => [ |
| 261 |
'' => esc_html__( 'Normal', 'elementor' ), |
| 262 |
'multiply' => 'Multiply', |
| 263 |
'screen' => 'Screen', |
| 264 |
'overlay' => 'Overlay', |
| 265 |
'darken' => 'Darken', |
| 266 |
'lighten' => 'Lighten', |
| 267 |
'color-dodge' => 'Color Dodge', |
| 268 |
'saturation' => 'Saturation', |
| 269 |
'color' => 'Color', |
| 270 |
'difference' => 'Difference', |
| 271 |
'exclusion' => 'Exclusion', |
| 272 |
'hue' => 'Hue', |
| 273 |
'luminosity' => 'Luminosity', |
| 274 |
], |
| 275 |
'selectors' => [ |
| 276 |
'{{WRAPPER}} .elementor-heading-title' => 'mix-blend-mode: {{VALUE}}', |
| 277 |
], |
| 278 |
'separator' => 'none', |
| 279 |
] |
| 280 |
); |
| 281 |
|
| 282 |
$this->end_controls_section(); |
| 283 |
} |
| 284 |
|
| 285 |
/** |
| 286 |
* Render heading widget output on the frontend. |
| 287 |
* |
| 288 |
* Written in PHP and used to generate the final HTML. |
| 289 |
* |
| 290 |
* @since 1.0.0 |
| 291 |
* @access protected |
| 292 |
*/ |
| 293 |
protected function render() { |
| 294 |
$settings = $this->get_settings_for_display(); |
| 295 |
|
| 296 |
if ( '' === $settings['title'] ) { |
| 297 |
return; |
| 298 |
} |
| 299 |
|
| 300 |
$this->add_render_attribute( 'title', 'class', 'elementor-heading-title' ); |
| 301 |
|
| 302 |
if ( ! empty( $settings['size'] ) ) { |
| 303 |
$this->add_render_attribute( 'title', 'class', 'elementor-size-' . $settings['size'] ); |
| 304 |
} |
| 305 |
|
| 306 |
$this->add_inline_editing_attributes( 'title' ); |
| 307 |
|
| 308 |
$title = $settings['title']; |
| 309 |
|
| 310 |
if ( ! empty( $settings['link']['url'] ) ) { |
| 311 |
$this->add_link_attributes( 'url', $settings['link'] ); |
| 312 |
|
| 313 |
$title = sprintf( '<a %1$s>%2$s</a>', $this->get_render_attribute_string( 'url' ), $title ); |
| 314 |
} |
| 315 |
|
| 316 |
$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 ); |
| 317 |
|
| 318 |
// PHPCS - the variable $title_html holds safe data. |
| 319 |
echo $title_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 320 |
} |
| 321 |
|
| 322 |
/** |
| 323 |
* Render heading widget output in the editor. |
| 324 |
* |
| 325 |
* Written as a Backbone JavaScript template and used to generate the live preview. |
| 326 |
* |
| 327 |
* @since 2.9.0 |
| 328 |
* @access protected |
| 329 |
*/ |
| 330 |
protected function content_template() { |
| 331 |
?> |
| 332 |
<# |
| 333 |
var title = settings.title; |
| 334 |
|
| 335 |
if ( '' !== settings.link.url ) { |
| 336 |
title = '<a href="' + settings.link.url + '">' + title + '</a>'; |
| 337 |
} |
| 338 |
|
| 339 |
view.addRenderAttribute( 'title', 'class', [ 'elementor-heading-title', 'elementor-size-' + settings.size ] ); |
| 340 |
|
| 341 |
view.addInlineEditingAttributes( 'title' ); |
| 342 |
|
| 343 |
var headerSizeTag = elementor.helpers.validateHTMLTag( settings.header_size ), |
| 344 |
title_html = '<' + headerSizeTag + ' ' + view.getRenderAttributeString( 'title' ) + '>' + title + '</' + headerSizeTag + '>'; |
| 345 |
|
| 346 |
print( title_html ); |
| 347 |
#> |
| 348 |
<?php |
| 349 |
} |
| 350 |
} |
| 351 |
|