PluginProbe
Easy Elements for Elementor – Addons & Website Templates / 1.3.3
Easy Elements for Elementor – Addons & Website Templates v1.3.3
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.3.3, at widgets/social-icon/social.php

520 lines 13.8 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 // Border Control
305 $this->add_group_control(
306 Group_Control_Border::get_type(),
307 [
308 'name' => 'button_border',
309 'selector' => '{{WRAPPER}} .eel-social-button',
310 ]
311 );
312
313 // Box Shadow Control
314 $this->add_group_control(
315 Group_Control_Box_Shadow::get_type(),
316 [
317 'name' => 'button_box_shadow',
318 'selector' => '{{WRAPPER}} .eel-social-button',
319 ]
320 );
321
322 // Global Background Color Control (only when global mode is selected)
323 $this->add_control(
324 'button_background_color',
325 [
326 'label' => esc_html__( 'Background Color', 'easy-elements' ),
327 'type' => Controls_Manager::COLOR,
328 'default' => '#1877F2',
329 'condition' => [
330 'color_mode' => 'global',
331 ],
332 'selectors' => [
333 '{{WRAPPER}} .eel-social-button' => 'background-color: {{VALUE}} !important;',
334 ],
335 ]
336 );
337
338 // Global Hover Background Color Control
339 $this->add_control(
340 'button_background_hover_color',
341 [
342 'label' => esc_html__( 'Hover Background Color', 'easy-elements' ),
343 'type' => Controls_Manager::COLOR,
344 'default' => '#166fe5',
345 'condition' => [
346 'color_mode' => 'global',
347 ],
348 'selectors' => [
349 '{{WRAPPER}} .eel-social-button:hover' => 'background-color: {{VALUE}} !important; border-color: {{VALUE}} !important;',
350 ],
351 ]
352 );
353
354 // Global Icon Color Control
355 $this->add_control(
356 'button_icon_color',
357 [
358 'label' => esc_html__( 'Icon Color', 'easy-elements' ),
359 'type' => Controls_Manager::COLOR,
360 'default' => '#ffffff',
361 'condition' => [
362 'color_mode' => 'global',
363 ],
364 'selectors' => [
365 '{{WRAPPER}} .eel-social-button i' => 'color: {{VALUE}};',
366 '{{WRAPPER}} .eel-social-button svg' => 'fill: {{VALUE}};',
367 ],
368 ]
369 );
370
371 // Global Hover Icon Color Control
372 $this->add_control(
373 'button_icon_hover_color',
374 [
375 'label' => esc_html__( 'Hover Icon Color', 'easy-elements' ),
376 'type' => Controls_Manager::COLOR,
377 'default' => '#ffffff',
378 'condition' => [
379 'color_mode' => 'global',
380 ],
381 'selectors' => [
382 '{{WRAPPER}} .eel-social-button:hover i' => 'color: {{VALUE}} !important;',
383 '{{WRAPPER}} .eel-social-button:hover svg' => 'fill: {{VALUE}} !important;',
384 ],
385 ]
386 );
387
388 // Icon Size Control
389 $this->add_responsive_control(
390 'icon_size',
391 [
392 'label' => esc_html__( 'Icon Size', 'easy-elements' ),
393 'type' => Controls_Manager::SLIDER,
394 'size_units' => [ 'px', 'em' ],
395 'range' => [
396 'px' => [
397 'min' => 10,
398 'max' => 50,
399 'step' => 1,
400 ],
401 'em' => [
402 'min' => 0.5,
403 'max' => 3,
404 'step' => 0.1,
405 ],
406 ],
407 'default' => [
408 'unit' => 'px',
409 'size' => 18,
410 ],
411 'selectors' => [
412 '{{WRAPPER}} .eel-social-button i' => 'font-size: {{SIZE}}{{UNIT}};',
413 '{{WRAPPER}} .eel-social-button svg' => 'width: {{SIZE}}{{UNIT}}; height: {{SIZE}}{{UNIT}};',
414 ],
415 ]
416 );
417
418 $this->end_controls_section();
419 }
420
421 /**
422 * Render widget output on the frontend
423 *
424 * Generates the HTML markup for the social icons
425 */
426 protected function render() {
427 $settings = $this->get_settings_for_display();
428
429 if ( empty( $settings['social_links'] ) ) {
430 return;
431 }
432
433 $color_mode = $settings['color_mode'] ?? 'custom';
434
435 echo '<div class="eel-social-share"><div class="eel-social-buttons">';
436
437 $custom_css = '';
438
439 foreach ( $settings['social_links'] as $index => $link ) {
440 $link_title = $link['link_title'] ?? '';
441 $link_url = $link['link_url']['url'] ?? '#';
442 $is_external = $link['link_url']['is_external'] ?? false;
443 $nofollow = $link['link_url']['nofollow'] ?? false;
444
445 $target = $is_external ? '_blank' : '_self';
446 $rel = '';
447
448 if ( $is_external && $nofollow ) {
449 $rel = 'nofollow noopener';
450 } elseif ( $is_external ) {
451 $rel = 'noopener';
452 } elseif ( $nofollow ) {
453 $rel = 'nofollow';
454 }
455
456
457 $unique_class = 'eel-social-custom-' . $index;
458
459 $hover_bg = '#166fe5';
460 $hover_icon = '#ffffff';
461 $bg_color = '#1877F2';
462 $icon_color = '#ffffff';
463
464 if ( 'custom' === $color_mode ) {
465 $bg_color = $link['background_color'] ?? $bg_color;
466 $icon_color = $link['icon_color'] ?? $icon_color;
467 $hover_bg = $link['hover_background_color'] ?? $hover_bg;
468 $hover_icon = $link['hover_icon_color'] ?? $hover_icon;
469 }
470
471 $inline_style = sprintf(
472 'background-color: %s; color: %s;',
473 esc_attr( $bg_color ),
474 esc_attr( $icon_color )
475 );
476
477 echo '<a href="' . esc_url( $link_url ) . '" class="eel-social-button ' . esc_attr( $unique_class ) . '"';
478 echo ' target="' . esc_attr( $target ) . '"';
479 if ( $rel ) {
480 echo ' rel="' . esc_attr( $rel ) . '"';
481 }
482 echo ' title="' . esc_attr( $link_title ) . '"';
483 echo ' style="' . esc_attr( $inline_style ) . '"';
484 echo '>';
485 if ( $color_mode === 'custom' ) {
486 \Elementor\Icons_Manager::render_icon(
487 $link['icon'],
488 [
489 'aria-hidden' => 'true',
490 'style' => 'color:' . esc_attr( $icon_color ) . '; fill:' . esc_attr( $icon_color ) . ';',
491 ]
492 );
493 }else{
494 \Elementor\Icons_Manager::render_icon($link['icon'],['aria-hidden' => 'true']);
495 }
496
497 echo '</a>';
498
499 if ( 'custom' === $color_mode ) {
500 $custom_css .= sprintf(
501 '.%1$s:hover{background-color:%2$s!important;}.%1$s:hover i,.%1$s:hover svg{color:%3$s!important;fill:%3$s!important;}',
502 esc_attr( $unique_class ),
503 esc_attr( $hover_bg ),
504 esc_attr( $hover_icon )
505 );
506 }
507 }
508
509 echo '</div></div>';
510
511 if ( ! empty( $custom_css ) ) {
512 $handle = 'easyel-social-share-inline';
513 wp_register_style( $handle, false, [], EASYELEMENTS_VER );
514 wp_enqueue_style( $handle );
515 wp_add_inline_style( $handle, $custom_css );
516 }
517 }
518
519 }
520