PluginProbe
Easy Elements for Elementor – Addons & Website Templates / 1.0.7
Easy Elements for Elementor – Addons & Website Templates v1.0.7
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.0.7, at widgets/featured-image/featured-image.php

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