PluginProbe
Easy Elements for Elementor – Addons & Website Templates / 1.4.5
Easy Elements for Elementor – Addons & Website Templates v1.4.5
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 / social-icon / social.php

social.php in Easy Elements for Elementor – Addons & Website Templates 1.4.5, at widgets/social-icon/social.php

552 lines 14.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Easy Elements Social Icon Widget
4 *
5 * A custom Elementor widget for displaying social media icons with links.
6 * Features customizable colors, hover effects, and responsive design.
7 *
8 * @package EasyElements
9 * @since 1.0.0
10 */
11 namespace Easyel\EasyElements\Widgets;
12 use Elementor\Controls_Manager;
13 use Elementor\Widget_Base;
14 use Elementor\Group_Control_Typography;
15 use Elementor\Group_Control_Border;
16 use Elementor\Group_Control_Box_Shadow;
17
18 if ( ! defined( 'ABSPATH' ) ) {
19 exit;
20 }
21
22 /**
23 *
24 * Handles the social icon widget functionality for Elementor.
25 */
26 class Easyel_Social_Icon_Widget extends \Elementor\Widget_Base {
27
28 /**
29 * Get widget style dependencies
30 *
31 * Loads the CSS file for the widget styling
32 *
33 * @return array Array of style handles
34 */
35
36 /**
37 * Get widget name
38 *
39 * @return string Widget name
40 */
41 public function get_name() {
42 return 'eel-social-icon';
43 }
44
45 /**
46 * Get widget title
47 *
48 * @return string Widget title
49 */
50 public function get_title() {
51 return __( 'Social Icon', 'easy-elements' );
52 }
53
54 /**
55 * Get widget icon
56 *
57 * @return string Widget icon
58 */
59 public function get_icon() {
60 return 'easyicon easyelIcon-social-icons';
61 }
62
63 /**
64 * Get widget categories
65 *
66 * @return array Widget categories
67 */
68 public function get_categories() {
69 return [ 'easyelements_category' ];
70 }
71
72 public function get_style_depends() {
73 return [
74 'eel-social-icon',
75 ];
76 }
77
78
79 /**
80 * Register widget controls
81 *
82 * Defines all the controls for the widget
83 */
84
85 public function get_keywords() {
86 return [ 'social', 'icon', 'link', 'click', 'share' ];
87 }
88 protected function register_controls() {
89 // ========================================
90 // CONTENT SECTION - Social Settings
91 // ========================================
92 $this->start_controls_section(
93 'content_section',
94 [
95 'label' => esc_html__( 'Social Settings', 'easy-elements' ),
96 'tab' => Controls_Manager::TAB_CONTENT,
97 ]
98 );
99
100 $this->add_control(
101 'social_links',
102 [
103 'label' => esc_html__( 'Social Links', 'easy-elements' ),
104 'type' => Controls_Manager::REPEATER,
105 'fields' => [
106 // Link Title Field
107 [
108 'name' => 'link_title',
109 'label' => esc_html__( 'Link Title', 'easy-elements' ),
110 'type' => Controls_Manager::TEXT,
111 'default' => esc_html__( 'Social Link', 'easy-elements' ),
112 ],
113 // Link URL Field
114 [
115 'name' => 'link_url',
116 'label' => esc_html__( 'Link URL', 'easy-elements' ),
117 'type' => Controls_Manager::URL,
118 'default' => [
119 'url' => '#',
120 'is_external' => false,
121 'nofollow' => false,
122 ],
123 ],
124 // Icon Field
125 [
126 'name' => 'icon',
127 'label' => esc_html__( 'Icon', 'easy-elements' ),
128 'type' => Controls_Manager::ICONS,
129 'default' => [
130 'value' => 'fab fa-facebook-f',
131 'library' => 'fa-brands',
132 ],
133 ],
134 // Background Color Field
135 [
136 'name' => 'background_color',
137 'label' => esc_html__( 'Background Color', 'easy-elements' ),
138 'type' => Controls_Manager::COLOR,
139 'default' => '#1877F2',
140 ],
141 // Icon Color Field
142 [
143 'name' => 'icon_color',
144 'label' => esc_html__( 'Icon Color', 'easy-elements' ),
145 'type' => Controls_Manager::COLOR,
146 'default' => '#ffffff',
147 ],
148 // Hover Background Color Field
149 [
150 'name' => 'hover_background_color',
151 'label' => esc_html__( 'Hover Background Color', 'easy-elements' ),
152 'type' => Controls_Manager::COLOR,
153 'default' => '#166fe5',
154 ],
155 // Hover Icon Color Field
156 [
157 'name' => 'hover_icon_color',
158 'label' => esc_html__( 'Hover Icon Color', 'easy-elements' ),
159 'type' => Controls_Manager::COLOR,
160 'default' => '#ffffff',
161 ],
162 ],
163 // Default social links
164 'default' => [
165 [
166 'link_title' => esc_html__( 'Facebook', 'easy-elements' ),
167 'link_url' => [ 'url' => '#' ],
168 'icon' => [ 'value' => 'fab fa-facebook-f' ],
169 'background_color' => '#1877F2',
170 'icon_color' => '#ffffff',
171 'hover_background_color' => '#166fe5',
172 'hover_icon_color' => '#ffffff',
173 ],
174 [
175 'link_title' => esc_html__( 'Twitter', 'easy-elements' ),
176 'link_url' => [ 'url' => '#' ],
177 'icon' => [ 'value' => 'fab fa-twitter' ],
178 'background_color' => '#1DA1F2',
179 'icon_color' => '#ffffff',
180 'hover_background_color' => '#1a91da',
181 'hover_icon_color' => '#ffffff',
182 ],
183 [
184 'link_title' => esc_html__( 'Instagram', 'easy-elements' ),
185 'link_url' => [ 'url' => '#' ],
186 'icon' => [ 'value' => 'fab fa-instagram' ],
187 'background_color' => '#E4405F',
188 'icon_color' => '#ffffff',
189 'hover_background_color' => '#d63384',
190 'hover_icon_color' => '#ffffff',
191 ],
192 ],
193 'title_field' => '{{{ link_title }}}',
194 ]
195 );
196
197 // Color Mode Control
198 $this->add_control(
199 'color_mode',
200 [
201 'label' => esc_html__( 'Color Mode', 'easy-elements' ),
202 'type' => Controls_Manager::SELECT,
203 'default' => 'custom',
204 'options' => [
205 'custom' => esc_html__( 'Custom Colors (Per Item)', 'easy-elements' ),
206 'global' => esc_html__( 'Global Colors', 'easy-elements' ),
207 ],
208 'separator' => 'before',
209 ]
210 );
211
212 $this->end_controls_section();
213
214 // ========================================
215 // STYLE SECTION - Buttons Style
216 // ========================================
217 $this->start_controls_section(
218 'buttons_style_section',
219 [
220 'label' => esc_html__( 'Buttons Style', 'easy-elements' ),
221 'tab' => Controls_Manager::TAB_STYLE,
222 ]
223 );
224
225 // Button Size Control
226 $this->add_responsive_control(
227 'button_size',
228 [
229 'label' => esc_html__( 'Button Size', 'easy-elements' ),
230 'type' => Controls_Manager::SLIDER,
231 'size_units' => [ 'px', 'em' ],
232 'range' => [
233 'px' => [
234 'min' => 30,
235 'max' => 100,
236 'step' => 1,
237 ],
238 'em' => [
239 'min' => 2,
240 'max' => 6,
241 'step' => 0.1,
242 ],
243 ],
244 'default' => [
245 'unit' => 'px',
246 'size' => 45,
247 ],
248 'selectors' => [
249 '{{WRAPPER}} .eel-social-button' => 'width: {{SIZE}}{{UNIT}}; height: {{SIZE}}{{UNIT}}; line-height: {{SIZE}}{{UNIT}};',
250 ],
251 ]
252 );
253
254 // Button Spacing Control
255 $this->add_responsive_control(
256 'button_spacing',
257 [
258 'label' => esc_html__( 'Button Spacing', 'easy-elements' ),
259 'type' => Controls_Manager::SLIDER,
260 'size_units' => [ 'px', 'em' ],
261 'range' => [
262 'px' => [
263 'min' => 0,
264 'max' => 50,
265 'step' => 1,
266 ],
267 'em' => [
268 'min' => 0,
269 'max' => 3,
270 'step' => 0.1,
271 ],
272 ],
273 'default' => [
274 'unit' => 'px',
275 'size' => 10,
276 ],
277 'selectors' => [
278 '{{WRAPPER}} .eel-social-buttons' => 'gap: {{SIZE}}{{UNIT}};',
279 ],
280 ]
281 );
282
283 // Border Radius Control
284 $this->add_control(
285 'button_border_radius',
286 [
287 'label' => esc_html__( 'Border Radius', 'easy-elements' ),
288 'type' => Controls_Manager::DIMENSIONS,
289 'size_units' => [ 'px', '%' ],
290 'default' => [
291 'top' => '50',
292 'right' => '50',
293 'bottom' => '50',
294 'left' => '50',
295 'unit' => '%',
296 'isLinked' => true,
297 ],
298 'selectors' => [
299 '{{WRAPPER}} .eel-social-button' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
300 ],
301 ]
302 );
303
304 // 1. Start the Tabs Wrapper
305 $this->start_controls_tabs( 'tabs_button_border_style' );
306
307 // ---- NORMAL STATE TAB ----
308 $this->start_controls_tab(
309 'tab_button_border_normal',
310 [
311 'label' => esc_html__( 'Normal', 'easy-elements' ),
312 ]
313 );
314
315 $this->add_group_control(
316 Group_Control_Border::get_type(),
317 [
318 'name' => 'button_border',
319 'selector' => '{{WRAPPER}} .eel-social-button',
320 ]
321 );
322
323 $this->end_controls_tab();
324
325 // ---- HOVER STATE TAB ----
326 $this->start_controls_tab(
327 'tab_button_border_hover',
328 [
329 'label' => esc_html__( 'Hover', 'easy-elements' ),
330 ]
331 );
332
333 $this->add_group_control(
334 Group_Control_Border::get_type(),
335 [
336 'name' => 'button_border_hover', // Must be a unique name
337 'selector' => '{{WRAPPER}} .eel-social-button:hover', // Targeted with :hover
338 ]
339 );
340
341 $this->end_controls_tab();
342
343 $this->end_controls_tabs(); // Close the Tabs Wrapper
344
345 // Box Shadow Control
346 $this->add_group_control(
347 Group_Control_Box_Shadow::get_type(),
348 [
349 'name' => 'button_box_shadow',
350 'selector' => '{{WRAPPER}} .eel-social-button',
351 ]
352 );
353
354 // Global Background Color Control (only when global mode is selected)
355 $this->add_control(
356 'button_background_color',
357 [
358 'label' => esc_html__( 'Background Color', 'easy-elements' ),
359 'type' => Controls_Manager::COLOR,
360 'default' => '#1877F2',
361 'condition' => [
362 'color_mode' => 'global',
363 ],
364 'selectors' => [
365 '{{WRAPPER}} .eel-social-button' => 'background-color: {{VALUE}} !important;',
366 ],
367 ]
368 );
369
370 // Global Hover Background Color Control
371 $this->add_control(
372 'button_background_hover_color',
373 [
374 'label' => esc_html__( 'Hover Background Color', 'easy-elements' ),
375 'type' => Controls_Manager::COLOR,
376 'default' => '#166fe5',
377 'condition' => [
378 'color_mode' => 'global',
379 ],
380 'selectors' => [
381 '{{WRAPPER}} .eel-social-button:hover' => 'background-color: {{VALUE}} !important; border-color: {{VALUE}} !important;',
382 ],
383 ]
384 );
385
386 // Global Icon Color Control
387 $this->add_control(
388 'button_icon_color',
389 [
390 'label' => esc_html__( 'Icon Color', 'easy-elements' ),
391 'type' => Controls_Manager::COLOR,
392 'default' => '#ffffff',
393 'condition' => [
394 'color_mode' => 'global',
395 ],
396 'selectors' => [
397 '{{WRAPPER}} .eel-social-button i' => 'color: {{VALUE}};',
398 '{{WRAPPER}} .eel-social-button svg' => 'fill: {{VALUE}};',
399 ],
400 ]
401 );
402
403 // Global Hover Icon Color Control
404 $this->add_control(
405 'button_icon_hover_color',
406 [
407 'label' => esc_html__( 'Hover Icon Color', 'easy-elements' ),
408 'type' => Controls_Manager::COLOR,
409 'default' => '#ffffff',
410 'condition' => [
411 'color_mode' => 'global',
412 ],
413 'selectors' => [
414 '{{WRAPPER}} .eel-social-button:hover i' => 'color: {{VALUE}} !important;',
415 '{{WRAPPER}} .eel-social-button:hover svg' => 'fill: {{VALUE}} !important;',
416 ],
417 ]
418 );
419
420 // Icon Size Control
421 $this->add_responsive_control(
422 'icon_size',
423 [
424 'label' => esc_html__( 'Icon Size', 'easy-elements' ),
425 'type' => Controls_Manager::SLIDER,
426 'size_units' => [ 'px', 'em' ],
427 'range' => [
428 'px' => [
429 'min' => 10,
430 'max' => 50,
431 'step' => 1,
432 ],
433 'em' => [
434 'min' => 0.5,
435 'max' => 3,
436 'step' => 0.1,
437 ],
438 ],
439 'default' => [
440 'unit' => 'px',
441 'size' => 18,
442 ],
443 'selectors' => [
444 '{{WRAPPER}} .eel-social-button i' => 'font-size: {{SIZE}}{{UNIT}};',
445 '{{WRAPPER}} .eel-social-button svg' => 'width: {{SIZE}}{{UNIT}}; height: {{SIZE}}{{UNIT}};',
446 ],
447 ]
448 );
449
450 $this->end_controls_section();
451 }
452
453 /**
454 * Render widget output on the frontend
455 *
456 * Generates the HTML markup for the social icons
457 */
458 protected function render() {
459 $settings = $this->get_settings_for_display();
460
461 if ( empty( $settings['social_links'] ) ) {
462 return;
463 }
464
465 $color_mode = $settings['color_mode'] ?? 'custom';
466
467 echo '<div class="eel-social-share"><div class="eel-social-buttons">';
468
469 $custom_css = '';
470
471 foreach ( $settings['social_links'] as $index => $link ) {
472 $link_title = $link['link_title'] ?? '';
473 $link_url = $link['link_url']['url'] ?? '#';
474 $is_external = $link['link_url']['is_external'] ?? false;
475 $nofollow = $link['link_url']['nofollow'] ?? false;
476
477 $target = $is_external ? '_blank' : '_self';
478 $rel = '';
479
480 if ( $is_external && $nofollow ) {
481 $rel = 'nofollow noopener';
482 } elseif ( $is_external ) {
483 $rel = 'noopener';
484 } elseif ( $nofollow ) {
485 $rel = 'nofollow';
486 }
487
488
489 $unique_class = 'eel-social-custom-' . $index;
490
491 $hover_bg = '#166fe5';
492 $hover_icon = '#ffffff';
493 $bg_color = '#1877F2';
494 $icon_color = '#ffffff';
495
496 if ( 'custom' === $color_mode ) {
497 $bg_color = $link['background_color'] ?? $bg_color;
498 $icon_color = $link['icon_color'] ?? $icon_color;
499 $hover_bg = $link['hover_background_color'] ?? $hover_bg;
500 $hover_icon = $link['hover_icon_color'] ?? $hover_icon;
501 }
502
503 $inline_style = sprintf(
504 'background-color: %s; color: %s;',
505 esc_attr( $bg_color ),
506 esc_attr( $icon_color )
507 );
508
509 echo '<a href="' . esc_url( $link_url ) . '" class="eel-social-button ' . esc_attr( $unique_class ) . '"';
510 echo ' target="' . esc_attr( $target ) . '"';
511 if ( $rel ) {
512 echo ' rel="' . esc_attr( $rel ) . '"';
513 }
514 echo ' title="' . esc_attr( $link_title ) . '"';
515 echo ' style="' . esc_attr( $inline_style ) . '"';
516 echo '>';
517 if ( $color_mode === 'custom' ) {
518 \Elementor\Icons_Manager::render_icon(
519 $link['icon'],
520 [
521 'aria-hidden' => 'true',
522 'style' => 'color:' . esc_attr( $icon_color ) . '; fill:' . esc_attr( $icon_color ) . ';',
523 ]
524 );
525 }else{
526 \Elementor\Icons_Manager::render_icon($link['icon'],['aria-hidden' => 'true']);
527 }
528
529 echo '</a>';
530
531 if ( 'custom' === $color_mode ) {
532 $custom_css .= sprintf(
533 '.%1$s:hover{background-color:%2$s!important;}.%1$s:hover i,.%1$s:hover svg{color:%3$s!important;fill:%3$s!important;}',
534 esc_attr( $unique_class ),
535 esc_attr( $hover_bg ),
536 esc_attr( $hover_icon )
537 );
538 }
539 }
540
541 echo '</div></div>';
542
543 if ( ! empty( $custom_css ) ) {
544 $handle = 'easyel-social-share-inline';
545 wp_register_style( $handle, false, [], EASYELEMENTS_VER );
546 wp_enqueue_style( $handle );
547 wp_add_inline_style( $handle, $custom_css );
548 }
549 }
550
551 }
552