PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.8.0
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.8.0
3.8.0 3.7.5 3.7.4 3.7.3 3.7.2 1-final 3.7.1 3.7.0 3.6.8 3.6.7 3.6.6 3.6.5 3.6.4 3.6.3 3.6.2 3.6.1 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 All 112 releases
templately / modules / theme-builder / Widgets / Featured_Image.php

Featured_Image.php in Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! 3.8.0, at modules/theme-builder/Widgets/Featured_Image.php

306 lines 7.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Templately\Modules\ThemeBuilder\Widgets;
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit; // Exit if accessed directly.
6 }
7
8 use Elementor\Controls_Manager;
9 use Elementor\Group_Control_Border;
10 use Elementor\Group_Control_Box_Shadow;
11 use Elementor\Group_Control_Image_Size;
12 use Elementor\Plugin;
13 use Elementor\Widget_Base;
14
15 class Featured_Image extends Widget_Base {
16
17 public function get_name() {
18 return 'tl-post-fatured-image';
19 }
20
21 public function get_title() {
22 return esc_html__( 'Featured Image', 'templately' );
23 }
24
25 public function get_icon() {
26 return 'eicon-featured-image templately-widget-icon';
27 }
28
29 public function get_categories() {
30 return [ 'templately' ];
31 }
32
33 // Hidden from the widget panel by default — surfaced per-document for the
34 // templately_library CPT via ThemeBuilder::elementor_document_config().
35 public function show_in_panel() {
36 return false;
37 }
38
39 public function get_keywords() {
40 return [ 'featured image', 'image', 'featured' ];
41 }
42
43 protected function register_controls() {
44 $this->start_controls_section(
45 'section_title',
46 [
47 'label' => esc_html__( 'Featured Image', 'templately' ),
48 ]
49 );
50
51 $this->add_group_control(
52 Group_Control_Image_Size::get_type(),
53 [
54 'name' => 'image',
55 'default' => 'full',
56 'exclude' => [ 'custom' ]
57 ]
58 );
59
60 $this->end_controls_section();
61
62 $this->start_controls_section(
63 'section_image_style',
64 [
65 'label' => esc_html__( 'Image', 'templately' ),
66 'tab' => Controls_Manager::TAB_STYLE,
67 ]
68 );
69
70 $this->add_responsive_control(
71 'align',
72 [
73 'label' => esc_html__( 'Alignment', 'templately' ),
74 'type' => Controls_Manager::CHOOSE,
75 'options' => [
76 'left' => [
77 'title' => esc_html__( 'Left', 'templately' ),
78 'icon' => 'eicon-text-align-left',
79 ],
80 'center' => [
81 'title' => esc_html__( 'Center', 'templately' ),
82 'icon' => 'eicon-text-align-center',
83 ],
84 'right' => [
85 'title' => esc_html__( 'Right', 'templately' ),
86 'icon' => 'eicon-text-align-right',
87 ],
88 ],
89 'selectors' => [
90 '{{WRAPPER}}' => 'text-align: {{VALUE}};',
91 ],
92 ]
93 );
94
95 $this->add_responsive_control(
96 'width',
97 [
98 'label' => esc_html__( 'Width', 'templately' ),
99 'type' => Controls_Manager::SLIDER,
100 'default' => [
101 'unit' => '%',
102 ],
103 'tablet_default' => [
104 'unit' => '%',
105 ],
106 'mobile_default' => [
107 'unit' => '%',
108 ],
109 'size_units' => [ 'px', '%', 'em', 'rem', 'vw', 'custom' ],
110 'range' => [
111 '%' => [
112 'min' => 1,
113 'max' => 100,
114 ],
115 'px' => [
116 'min' => 1,
117 'max' => 1000,
118 ],
119 'vw' => [
120 'min' => 1,
121 'max' => 100,
122 ],
123 ],
124 'selectors' => [
125 '{{WRAPPER}} img' => 'width: {{SIZE}}{{UNIT}};',
126 ],
127 ]
128 );
129
130 $this->add_responsive_control(
131 'max-width',
132 [
133 'label' => esc_html__( 'Max Width', 'templately' ),
134 'type' => Controls_Manager::SLIDER,
135 'default' => [
136 'unit' => '%',
137 ],
138 'tablet_default' => [
139 'unit' => '%',
140 ],
141 'mobile_default' => [
142 'unit' => '%',
143 ],
144 'size_units' => [ 'px', '%', 'em', 'rem', 'vw', 'custom' ],
145 'range' => [
146 '%' => [
147 'min' => 1,
148 'max' => 100,
149 ],
150 'px' => [
151 'min' => 1,
152 'max' => 1000,
153 ],
154 'vw' => [
155 'min' => 1,
156 'max' => 100,
157 ],
158 ],
159 'selectors' => [
160 '{{WRAPPER}} img' => 'max-width: {{SIZE}}{{UNIT}};',
161 ],
162 ]
163 );
164
165 $this->add_responsive_control(
166 'height',
167 [
168 'label' => esc_html__( 'Height', 'templately' ),
169 'type' => Controls_Manager::SLIDER,
170 'size_units' => [ 'px', '%', 'em', 'rem', 'vh', 'custom' ],
171 'range' => [
172 'px' => [
173 'min' => 1,
174 'max' => 500,
175 ],
176 'vh' => [
177 'min' => 1,
178 'max' => 100,
179 ],
180 ],
181 'selectors' => [
182 '{{WRAPPER}} img' => 'height: {{SIZE}}{{UNIT}};',
183 ],
184 ]
185 );
186
187 $this->add_responsive_control(
188 'object-fit',
189 [
190 'label' => esc_html__( 'Object Fit', 'templately' ),
191 'type' => Controls_Manager::SELECT,
192 'condition' => [
193 'height[size]!' => '',
194 ],
195 'options' => [
196 '' => esc_html__( 'Default', 'templately' ),
197 'fill' => esc_html__( 'Fill', 'templately' ),
198 'cover' => esc_html__( 'Cover', 'templately' ),
199 'contain' => esc_html__( 'Contain', 'templately' ),
200 ],
201 'default' => '',
202 'selectors' => [
203 '{{WRAPPER}} img' => 'object-fit: {{VALUE}};',
204 ],
205 ]
206 );
207
208 $this->add_responsive_control(
209 'object-position',
210 [
211 'label' => esc_html__( 'Object Position', 'templately' ),
212 'type' => Controls_Manager::SELECT,
213 'options' => [
214 'center center' => esc_html__( 'Center Center', 'templately' ),
215 'center left' => esc_html__( 'Center Left', 'templately' ),
216 'center right' => esc_html__( 'Center Right', 'templately' ),
217 'top center' => esc_html__( 'Top Center', 'templately' ),
218 'top left' => esc_html__( 'Top Left', 'templately' ),
219 'top right' => esc_html__( 'Top Right', 'templately' ),
220 'bottom center' => esc_html__( 'Bottom Center', 'templately' ),
221 'bottom left' => esc_html__( 'Bottom Left', 'templately' ),
222 'bottom right' => esc_html__( 'Bottom Right', 'templately' ),
223 ],
224 'default' => 'center center',
225 'selectors' => [
226 '{{WRAPPER}} img' => 'object-position: {{VALUE}};',
227 ],
228 'condition' => [
229 'height[size]!' => '',
230 'object-fit' => 'cover',
231 ],
232 ]
233 );
234
235 $this->add_group_control(
236 Group_Control_Border::get_type(),
237 [
238 'name' => 'image_border',
239 'selector' => '{{WRAPPER}} img',
240 'separator' => 'before',
241 ]
242 );
243
244 $this->add_responsive_control(
245 'image_border_radius',
246 [
247 'label' => esc_html__( 'Border Radius', 'templately' ),
248 'type' => Controls_Manager::DIMENSIONS,
249 'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ],
250 'selectors' => [
251 '{{WRAPPER}} img' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
252 ],
253 ]
254 );
255
256 $this->add_group_control(
257 Group_Control_Box_Shadow::get_type(),
258 [
259 'name' => 'image_box_shadow',
260 'exclude' => [
261 'box_shadow_position',
262 ],
263 'selector' => '{{WRAPPER}} img',
264 ]
265 );
266
267 $this->end_controls_section();
268 }
269
270 protected function get_dynamic_post_ID() {
271 $post_type = 'post';
272 $type = get_post_meta( get_the_ID(), '_templately_template_type', true );
273 if($type == 'single') {
274 $post_type = 'post';
275 }
276 else if($type == 'page_single') {
277 $post_type = 'page';
278 }
279 else if($type == 'product_single') {
280 $post_type = 'product';
281 }
282 $latest_cpt = get_posts( "post_type=$post_type&numberposts=1" );
283
284 return Plugin::$instance->editor->is_edit_mode() || isset($_GET['templately_library'], $_GET['preview_id']) ? $latest_cpt[0]->ID : get_the_ID();
285 }
286
287 protected function render() {
288 $settings = $this->get_settings_for_display();
289 $size = $settings['image_size'];
290 $attachment_id = get_post_thumbnail_id( $this->get_dynamic_post_ID() );
291 $image_src = wp_get_attachment_image_src( $attachment_id, $size );
292 $image_src = $image_src[0] ?? '';
293 $image_title = get_the_title( $attachment_id );
294 $image_alt = get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ) ?? '';
295 $image_class_html = "attachment-{$size} size-{$size} wp-image-{$attachment_id}";
296
297 printf(
298 '<img src="%1$s" title="%2$s" alt="%3$s" class="%4$s" loading="lazy" />',
299 esc_url( $image_src ),
300 esc_attr( $image_title ),
301 esc_attr( $image_alt ),
302 esc_attr( $image_class_html )
303 );
304 }
305 }
306