PluginProbe
Easy Elements for Elementor – Addons & Website Templates / 1.5.0
Easy Elements for Elementor – Addons & Website Templates v1.5.0
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 / featured-image / featured-image.php

featured-image.php in Easy Elements for Elementor – Addons & Website Templates 1.5.0, at widgets/featured-image/featured-image.php

202 lines 6.3 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_free_Featured_Image_Widget extends \Elementor\Widget_Base {
11
12 public function get_name() {
13 return 'eel-featured-image';
14 }
15
16 public function get_title() {
17 return __( 'Featured Image', 'easy-elements' );
18 }
19
20 public function get_icon() {
21 return 'easyicon easyelIcon-image-carousel';
22 }
23
24 public function get_categories() {
25 return [ 'easyelements_category' ];
26 }
27 public function get_keywords() {
28 return [ 'image', 'thumbnail', 'link', 'featured' ];
29 }
30
31 public function get_style_depends() {
32 return [
33 'eel-featured-image',
34 ];
35 }
36
37 protected function register_controls() {
38
39 $this->start_controls_section(
40 'content_section',
41 [
42 'label' => esc_html__('Featured Image Settings', 'easy-elements'),
43 'tab' => Controls_Manager::TAB_CONTENT,
44 ]
45 );
46
47 $this->add_responsive_control(
48 'featured_image_width',
49 [
50 'label' => esc_html__('Width', 'easy-elements'),
51 'type' => Controls_Manager::SLIDER,
52 'size_units' => ['px', '%'],
53 'range' => [
54 'px' => [
55 'min' => 0,
56 'max' => 1000,
57 ],
58 '%' => [
59 'min' => 0,
60 'max' => 100,
61 ],
62 ],
63 'selectors' => [
64 '{{WRAPPER}} .eel-featured-image-inner img' => 'width: {{SIZE}}{{UNIT}};',
65 ],
66 ]
67 );
68
69 $this->add_responsive_control(
70 'featured_image_height',
71 [
72 'label' => esc_html__('Height', 'easy-elements'),
73 'type' => Controls_Manager::SLIDER,
74 'size_units' => ['px', '%'],
75 'range' => [
76 'px' => [
77 'min' => 100,
78 'max' => 1000,
79 ],
80 '%' => [
81 'min' => 100,
82 'max' => 100,
83 ],
84 ],
85 'selectors' => [
86 '{{WRAPPER}} .eel-featured-image-inner img' => 'height: {{SIZE}}{{UNIT}};',
87 ],
88 ]
89 );
90
91 $this->add_responsive_control(
92 'border_radius',
93 [
94 'label' => esc_html__('Border Radius', 'easy-elements'),
95 'type' => Controls_Manager::DIMENSIONS,
96 'size_units' => ['px'],
97 'range' => [
98 'px' => [
99 'min' => 0,
100 'max' => 100,
101 ],
102 ],
103 'selectors' => [
104 '.eel-featured-image-inner' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}} !important;',
105 ],
106 ]
107 );
108
109 // Image Size Control
110 $this->add_control(
111 'image_size',
112 [
113 'label' => esc_html__('Image Size', 'easy-elements'),
114 'type' => Controls_Manager::SELECT,
115 'default' => 'full',
116 'options' => [
117 'thumbnail' => esc_html__('Thumbnail', 'easy-elements'),
118 'medium' => esc_html__('Medium', 'easy-elements'),
119 'large' => esc_html__('Large', 'easy-elements'),
120 'full' => esc_html__('Full', 'easy-elements'),
121 ],
122 ]
123 );
124
125 // Add show/hide image link control
126 $this->add_control(
127 'show_image_link',
128 [
129 'label' => esc_html__('Show Image Link', 'easy-elements'),
130 'type' => Controls_Manager::SWITCHER,
131 'label_on' => esc_html__('Show', 'easy-elements'),
132 'label_off' => esc_html__('Hide', 'easy-elements'),
133 'return_value' => 'yes',
134 'default' => 'yes',
135 ]
136 );
137
138 $this->end_controls_section();
139
140 }
141
142 protected function render() {
143 $settings = $this->get_settings_for_display();
144 $image_size = $settings['image_size'] ?? 'full';
145 $editor_mode = \Elementor\Plugin::instance()->editor->is_edit_mode();
146 $wrapper_classes = 'eel-featured-image-wrapper' . ( $editor_mode ? ' ' : '' );
147
148 $post_id = function_exists('easyel_get_prepared_post_id')
149 ? easyel_get_prepared_post_id()
150 : ( isset($GLOBALS['post']->ID) ? $GLOBALS['post']->ID : 0 );
151 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
152 if ( !$post_id && isset($_GET['preview_id']) ) {
153 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
154 $post_id = intval(sanitize_text_field(wp_unslash($_GET['preview_id'])));
155 }
156
157 $image_url = '';
158 $image_alt = '';
159 $post_link = '';
160
161 if ( $post_id && has_post_thumbnail( $post_id ) ) {
162 $image_url = get_the_post_thumbnail_url( $post_id, $image_size );
163 $image_alt = get_the_title( $post_id );
164 $post_link = get_permalink( $post_id );
165 }
166
167 ?>
168 <div class="<?php echo esc_attr( $wrapper_classes ); ?>">
169 <div class="eel-featured-image-inner">
170 <?php if ( !empty($image_url) ) : ?>
171 <?php if ( ($settings['show_image_link'] ?? '') === 'yes' && !empty($post_link) ) : ?>
172 <a href="<?php echo esc_url( $post_link ); ?>" class="eel-featured-image-link">
173 <img src="<?php echo esc_url( $image_url ); ?>" alt="<?php echo esc_attr( $image_alt ?: __('Featured Image', 'easy-elements') ); ?>" class="eel-featured-image-img" loading="lazy" />
174 </a>
175 <?php else : ?>
176 <img src="<?php echo esc_url( $image_url ); ?>" alt="<?php echo esc_attr( $image_alt ?: __('Featured Image', 'easy-elements') ); ?>" class="eel-featured-image-img" loading="lazy" />
177 <?php endif; ?>
178 <?php elseif ( $editor_mode ) : ?>
179 <div class="eel-featured-image-placeholder">
180 <svg width="64" height="64" viewBox="0 0 64 64" fill="none" xmlns="http://www.w3.org/2000/svg" class="eel-featured-image-placeholder-icon">
181 <defs>
182 <linearGradient id="imgGradient" x1="0" y1="0" x2="64" y2="64" gradientUnits="userSpaceOnUse">
183 <stop stop-color="#7fd7ff"/>
184 <stop offset="1" stop-color="#0073e6"/>
185 </linearGradient>
186 </defs>
187 <rect x="8" y="14" width="48" height="36" rx="5" fill="#f0f6ff" stroke="url(#imgGradient)" stroke-width="2.5"/>
188 <circle cx="22" cy="28" r="5" fill="#b3d4fc" />
189 <path d="M14 44L26 32L36 42L44 34L52 42" stroke="#b3d4fc" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"/>
190 </svg>
191 <div class="eel-featured-image-placeholder-title"><?php esc_html_e('No Featured Image', 'easy-elements'); ?></div>
192 <div class="eel-featured-image-placeholder-desc"><?php esc_html_e('Please add a featured image to display here.', 'easy-elements'); ?></div>
193 <a href="#" class="eel-featured-image-placeholder-btn" tabindex="-1"><?php esc_html_e('Set Featured Image', 'easy-elements'); ?></a>
194 </div>
195 <?php endif; ?>
196 </div>
197 </div>
198 <?php
199 }
200
201 }
202