PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.5.1
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.5.1
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 3.1.10 All 111 releases
templately / includes / Builder / Widgets / Site_Logo.php

Site_Logo.php in Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! 3.5.1, at includes/Builder/Widgets/Site_Logo.php

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