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 / Site_Logo.php

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

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