PluginProbe
Easy Elements for Elementor – Addons & Website Templates / 1.3.4
Easy Elements for Elementor – Addons & Website Templates v1.3.4
1.5.3 1.5.2 1.5.1 1.5.0 1.4.9 1.4.6 1.4.7 1.4.8 1.4.5 1.4.4 1.4.3 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 All 47 releases
easy-elements / widgets / page-title / page-title.php

page-title.php in Easy Elements for Elementor – Addons & Website Templates 1.3.4, at widgets/page-title/page-title.php

403 lines 12.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Easyel\EasyElements\Widgets;
3 use Elementor\Controls_Manager;
4 use Elementor\Widget_Base;
5
6 if ( ! defined( 'ABSPATH' ) ) {
7 exit;
8 }
9
10 class Easyel_Page_Title_Widget extends \Elementor\Widget_Base {
11
12 public function get_name() {
13 return 'eel-page-title';
14 }
15
16 public function get_title() {
17 return __( 'Page Title', 'easy-elements' );
18 }
19
20 public function get_icon() {
21 return 'easyicon easyelIcon-page-title';
22 }
23
24 public function get_categories() {
25 return [ 'easyelements_header_footer_category' ];
26 }
27
28 public function get_keywords() {
29 return [ 'page', 'link', 'title', 'text' ];
30 }
31
32 public function get_style_depends() {
33 return [
34 'eel-page-title',
35 ];
36 }
37
38
39
40 protected function register_controls() {
41
42 $this->start_controls_section(
43 'content_section',
44 [
45 'label' => esc_html__('Page Title Settings', 'easy-elements'),
46 'tab' => Controls_Manager::TAB_CONTENT,
47 ]
48 );
49
50 $this->add_control(
51 'custom_title_show_hide',
52 [
53 'label' => esc_html__('Show Page Title', 'easy-elements'),
54 'type' => Controls_Manager::SWITCHER,
55 'default' => 'yes',
56 'label_on' => esc_html__('Show', 'easy-elements'),
57 'label_off' => esc_html__('Hide', 'easy-elements'),
58 'return_value' => 'yes',
59 ]
60 );
61
62 $this->add_control(
63 'custom_title',
64 [
65 'label' => esc_html__('Custom Page Title', 'easy-elements'),
66 'type' => Controls_Manager::TEXTAREA,
67 'label_block' => true,
68 'default' => '',
69 'placeholder' => esc_html__('Enter custom title (leave blank for page title)', 'easy-elements'),
70 'condition' => [
71 'custom_title_show_hide' => 'yes',
72 ],
73 ]
74 );
75
76 $this->add_control(
77 'heading_title',
78 [
79 'label' => esc_html__('Custom Heading Title Under Page Title', 'easy-elements'),
80 'type' => Controls_Manager::TEXTAREA,
81 'label_block' => true,
82 'description' => esc_html__('Enter heading title (You can show heading title under the title). Use {{Entro}} to highlight specific words with different color.', 'easy-elements'),
83 ]
84 );
85
86 $this->add_control(
87 'custom_description',
88 [
89 'label' => esc_html__('Custom Description Under Page Title', 'easy-elements'),
90 'type' => Controls_Manager::TEXTAREA,
91 'default' => '',
92 'placeholder' => esc_html__('Enter description', 'easy-elements'),
93 ]
94 );
95
96 $this->add_control(
97 'title_size',
98 [
99 'label' => esc_html__('Title Size', 'easy-elements'),
100 'type' => Controls_Manager::SELECT,
101 'label_block' => true,
102 'default' => 'large',
103 'options' => [
104 'small' => esc_html__('Small', 'easy-elements'),
105 'large' => esc_html__('Large', 'easy-elements')
106 ]
107 ]
108 );
109
110
111 $this->add_control(
112 'title_tag',
113 [
114 'label' => esc_html__('Title HTML Tag', 'easy-elements'),
115 'type' => Controls_Manager::SELECT,
116 'options' => [
117 'h1' => 'H1',
118 'h2' => 'H2',
119 'h3' => 'H3',
120 'div' => 'Div',
121 'span' => 'Span',
122 'p' => 'Paragraph',
123 ],
124 'default' => 'h1',
125 ]
126 );
127
128 $this->add_control(
129 'heading_title_tag',
130 [
131 'label' => esc_html__('Heading Title HTML Tag', 'easy-elements'),
132 'type' => Controls_Manager::SELECT,
133 'default' => 'h2',
134 'options' => [
135 'h1' => 'H1',
136 'h2' => 'H2',
137 'h3' => 'H3',
138 'div' => 'Div',
139 'span' => 'Span',
140 'p' => 'Paragraph',
141 ],
142 ]
143 );
144
145 $this->add_responsive_control(
146 'alignment',
147 [
148 'label' => esc_html__('Alignment', 'easy-elements'),
149 'type' => Controls_Manager::CHOOSE,
150 'options' => [
151 'left' => [
152 'title' => __('Left', 'easy-elements'),
153 'icon' => 'eicon-text-align-left',
154 ],
155 'center' => [
156 'title' => __('Center', 'easy-elements'),
157 'icon' => 'eicon-text-align-center',
158 ],
159 'right' => [
160 'title' => __('Right', 'easy-elements'),
161 'icon' => 'eicon-text-align-right',
162 ],
163 ],
164 'default' => 'left',
165 'separator' => 'after',
166 'selectors' => [
167 '{{WRAPPER}} .eel-page-title-wrapper' => 'text-align: {{VALUE}};',
168 ],
169 'toggle' => true,
170 ]
171 );
172
173 $this->add_control(
174 'border_show_hide',
175 [
176 'label' => esc_html__('Border Show/Hide', 'easy-elements'),
177 'type' => Controls_Manager::SWITCHER,
178 'default' => 'yes',
179 'label_on' => esc_html__('Show', 'easy-elements'),
180 'label_off' => esc_html__('Hide', 'easy-elements'),
181 'return_value' => 'yes',
182 ]
183 );
184
185 $this->add_control(
186 'border_position',
187 [
188 'label' => esc_html__('Border Position', 'easy-elements'),
189 'type' => Controls_Manager::SELECT,
190 'options' => [
191 'left' => esc_html__('Left', 'easy-elements'),
192 'right' => esc_html__('Right', 'easy-elements'),
193 ],
194 'default' => 'left',
195 'condition' => [
196 'border_show_hide' => 'yes',
197 ],
198 ]
199 );
200
201 $this->add_control(
202 'boder_color',
203 [
204 'label' => esc_html__('Border Color', 'easy-elements'),
205 'type' => Controls_Manager::COLOR,
206 'condition' => [
207 'border_show_hide' => 'yes',
208 ],
209 'selectors' => [
210 '{{WRAPPER}} .eel-border-left' => 'background: {{VALUE}};',
211 ],
212 ]
213 );
214
215
216 $this->add_control(
217 'title_color',
218 [
219 'label' => esc_html__('Title Color', 'easy-elements'),
220 'type' => Controls_Manager::COLOR,
221 'separator' => 'before',
222 'selectors' => [
223 '{{WRAPPER}} .eel-page-title' => 'color: {{VALUE}};',
224 ],
225 ]
226 );
227
228 $this->add_group_control(
229 \Elementor\Group_Control_Typography::get_type(),
230 [
231 'name' => 'title_typography',
232 'selector' => '{{WRAPPER}} .eel-page-title',
233 ]
234 );
235 $this->add_responsive_control(
236 'title_margin',
237 [
238 'label' => esc_html__('Title Margin', 'easy-elements'),
239 'type' => Controls_Manager::DIMENSIONS,
240 'size_units' => [ 'px', '%', 'em' ],
241 'default' => [
242 'top' => '0',
243 'right' => '0',
244 'bottom' => '0',
245 'left' => '0',
246 'unit' => 'px',
247 ],
248 'selectors' => [
249 '{{WRAPPER}} .eel-page-title' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
250 ],
251 ]
252 );
253
254 $this->add_control(
255 'heading_title_color',
256 [
257 'label' => esc_html__('Heading Title Color', 'easy-elements'),
258 'type' => Controls_Manager::COLOR,
259 'separator' => 'before',
260 'selectors' => [
261 '{{WRAPPER}} .eel-heading-title' => 'color: {{VALUE}};',
262 ],
263 ]
264 );
265
266 $this->add_group_control(
267 \Elementor\Group_Control_Typography::get_type(),
268 [
269 'name' => 'heading_title_typography',
270 'selector' => '{{WRAPPER}} .eel-heading-title',
271 ]
272 );
273
274 $this->add_responsive_control(
275 'heading_title_margin',
276 [
277 'label' => esc_html__('Heading Title Margin', 'easy-elements'),
278 'type' => Controls_Manager::DIMENSIONS,
279 'selectors' => [
280 '{{WRAPPER}} .eel-heading-title' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
281 ],
282 ]
283 );
284
285 $this->add_control(
286 'highlighted_span_color',
287 [
288 'label' => esc_html__('Highlighted Color', 'easy-elements'),
289 'type' => Controls_Manager::COLOR,
290 'description' => esc_html__('Color for text wrapped in {{}} brackets. Example: "An {{experienced team}} for your business"', 'easy-elements'),
291 'selectors' => [
292 '{{WRAPPER}} .eel-highlighted' => 'color: {{VALUE}};',
293 ],
294 ]
295 );
296
297 $this->add_control(
298 'description_color',
299 [
300 'label' => esc_html__('Description Color', 'easy-elements'),
301 'type' => Controls_Manager::COLOR,
302 'separator' => 'before',
303 'selectors' => [
304 '{{WRAPPER}} .eel-page-description' => 'color: {{VALUE}};',
305 ],
306 ]
307 );
308
309 $this->add_group_control(
310 \Elementor\Group_Control_Typography::get_type(),
311 [
312 'name' => 'description_typography',
313 'selector' => '{{WRAPPER}} .eel-page-description',
314 ]
315 );
316
317 $this->add_responsive_control(
318 'description_margin',
319 [
320 'label' => esc_html__('Description Margin', 'easy-elements'),
321 'type' => Controls_Manager::DIMENSIONS,
322 'selectors' => [
323 '{{WRAPPER}} .eel-page-description' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
324 ],
325 ]
326 );
327 $this->end_controls_section();
328 }
329
330 /**
331 * Get the dynamic page title based on the current page context.
332 *
333 * @return string
334 */
335 private function get_dynamic_page_title() {
336 if ( is_home() ) {
337 return get_option( 'page_for_posts' ) ? get_the_title( get_option( 'page_for_posts' ) ) : __( 'Blog', 'easy-elements' );
338 } elseif ( is_category() ) {
339 return single_cat_title( '', false );
340 } elseif ( is_archive() ) {
341 return get_the_archive_title();
342 } elseif ( is_search() ) {
343 // translators: %s is the search query entered by the user.
344 return sprintf( __( 'Search Results for "%s"', 'easy-elements' ), get_search_query() );
345 } elseif ( is_404() ) {
346 return __( 'Page Not Found', 'easy-elements' );
347 } elseif ( is_tag() ) {
348 return single_tag_title( '', false );
349 } elseif ( is_author() ) {
350 return get_the_author();
351 } elseif ( is_date() ) {
352 return get_the_date();
353 } elseif ( is_post_type_archive() ) {
354 return post_type_archive_title( '', false );
355 } elseif ( is_singular() ) {
356 return get_the_title();
357 } else {
358 return get_the_title();
359 }
360 }
361
362
363 protected function render() {
364 $settings = $this->get_settings_for_display();
365 $title = (!empty($settings['custom_title']) && (!isset($settings['custom_title_show_hide']) || $settings['custom_title_show_hide'] === 'yes'))
366 ? $settings['custom_title']
367 : $this->get_dynamic_page_title();
368 $description = !empty($settings['custom_description']) ? $settings['custom_description'] : '';
369 $tag = !empty($settings['title_tag']) ? $settings['title_tag'] : 'h1';
370 $title_size = !empty($settings['title_size']) ? $settings['title_size'] : 'large';
371 $heading_title = !empty($settings['heading_title']) ? $settings['heading_title'] : '';
372 $heading_title_tag = !empty($settings['heading_title_tag']) ? $settings['heading_title_tag'] : 'h2';
373 $border_position = !empty($settings['border_position']) ? $settings['border_position'] : 'left';
374 $border_show_hide = !empty($settings['border_show_hide']) ? $settings['border_show_hide'] : '';
375
376 $processed_heading_title = '';
377 if (!empty($heading_title)) {
378 $processed_heading_title = preg_replace('/\{\{([^}]+)\}\}/', '<span class="eel-highlighted">$1</span>', $heading_title);
379 }
380 ?>
381 <div class="eel-page-title-wrapper eel-title-size-<?php echo esc_attr($title_size); ?> eel-border-position-<?php echo esc_attr($border_position); ?>">
382
383 <?php if ( isset( $settings['custom_title_show_hide']) && !empty( $settings['custom_title_show_hide'] ) && $settings['custom_title_show_hide'] === 'yes' ){ ?>
384 <<?php echo esc_attr($tag); ?> class="eel-page-title">
385 <?php if ($border_show_hide == 'yes') { ?>
386 <span class="eel-border-left"></span>
387 <?php } ?>
388 <?php echo wp_kses_post($title); ?>
389 </<?php echo esc_attr($tag); ?>>
390 <?php } ?>
391 <?php if ($heading_title): ?>
392 <<?php echo esc_attr($heading_title_tag); ?> class="eel-heading-title"><?php echo wp_kses_post($processed_heading_title); ?></<?php echo esc_attr($heading_title_tag); ?>>
393 <?php endif; ?>
394
395 <?php if ($description): ?>
396 <div class="eel-page-description"><?php echo wp_kses_post($description); ?></div>
397 <?php endif; ?>
398 </div>
399 <?php
400 }
401
402 }
403