PluginProbe
Easy Elements for Elementor – Addons & Website Templates / 1.2.7
Easy Elements for Elementor – Addons & Website Templates v1.2.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 / site-logo / site-logo.php

site-logo.php in Easy Elements for Elementor – Addons & Website Templates 1.2.7, at widgets/site-logo/site-logo.php

372 lines 12.1 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\Utils;
5 use Elementor\Widget_Base;
6 use Elementor\Group_Control_Typography;
7 use Elementor\Group_Control_Text_Shadow;
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit;
11 }
12
13 class Easyel_Site_Logo_Widget extends \Elementor\Widget_Base {
14
15 public function get_name() {
16 return 'eel-site-logo';
17 }
18
19 public function get_title() {
20 return __( 'Site Logo', 'easy-elements' );
21 }
22
23 public function get_icon() {
24 return 'easyicon easyelIcon-site-logo';
25 }
26
27 public function get_categories() {
28 return [ 'easyelements_header_footer_category' ];
29 }
30
31 public function get_keywords() {
32 return [ 'site', 'logo', 'link', 'image', 'text' ];
33 }
34
35 public function get_style_depends() {
36 return [
37 'eel-site-logo',
38 ];
39 }
40
41
42 protected function register_controls() {
43 $this->start_controls_section( 'section_logo', [
44 'label' => __( 'Site Logo Settings', 'easy-elements' ),
45 ] );
46 $this->add_control( 'site_logo_fallback', [
47 'label' => __( 'Use Custom Logo?', 'easy-elements' ),
48 'type' => Controls_Manager::SWITCHER,
49 'default' => '',
50 ] );
51 $this->add_control( 'custom_image', [
52 'label' => __( 'Custom Logo Image', 'easy-elements' ),
53 'type' => Controls_Manager::MEDIA,
54 'dynamic' => [ 'active' => true ],
55 'default' => [ 'url' => Utils::get_placeholder_image_src() ],
56 'condition' => [ 'site_logo_fallback' => 'yes' ],
57 ] );
58 $this->add_control( 'custom_sticky_image', [
59 'label' => __( 'Custom Sticky Logo Image', 'easy-elements' ),
60 'type' => Controls_Manager::MEDIA,
61 'dynamic' => [ 'active' => true ],
62 'default' => [ 'url' => Utils::get_placeholder_image_src() ],
63 'condition' => [ 'site_logo_fallback' => 'yes' ],
64 ] );
65 $this->add_responsive_control(
66 'logo_height',
67 [
68 'label' => esc_html__( 'Logo Width', 'easy-elements' ),
69 'type' => \Elementor\Controls_Manager::SLIDER,
70 'size_units' => [ 'px', '%', 'em', 'vh' ],
71 'range' => [
72 'px' => [
73 'min' => 10,
74 'max' => 500,
75 'step' => 1,
76 ],
77 '%' => [
78 'min' => 1,
79 'max' => 100,
80 ],
81 'em' => [
82 'min' => 0.1,
83 'max' => 10,
84 ],
85 ],
86 'default' => [
87 'unit' => 'px',
88 'size' => '',
89 ],
90 'selectors' => [
91 '{{WRAPPER}} .eel-site-logo a img, {{WRAPPER}} .eel-site-logo img' => 'width: {{SIZE}}{{UNIT}}; height: auto;',
92 ],
93 ]
94 );
95 $this->add_responsive_control( 'align', [
96 'label' => __( 'Alignment', 'easy-elements' ),
97 'type' => Controls_Manager::CHOOSE,
98 'options' => [
99 'left' => [ 'title' => __( 'Left', 'easy-elements' ), 'icon' => 'eicon-h-align-left' ],
100 'center' => [ 'title' => __( 'Center', 'easy-elements' ), 'icon' => 'eicon-h-align-center' ],
101 'right' => [ 'title' => __( 'Right', 'easy-elements' ), 'icon' => 'eicon-h-align-right' ],
102 ],
103 'default' => 'left',
104 'selectors' => [
105 '{{WRAPPER}} .eel-site-logo' => 'justify-content: {{VALUE}};',
106 ],
107 ] );
108 $this->add_control( 'caption_source', [
109 'label' => __( 'Show Caption?', 'easy-elements' ),
110 'type' => Controls_Manager::SWITCHER,
111 'default' => '',
112 ] );
113 $this->add_control( 'caption', [
114 'label' => __( 'Custom Caption', 'easy-elements' ),
115 'type' => Controls_Manager::TEXT,
116 'dynamic' => [ 'active' => true ],
117 'condition' => [ 'caption_source' => 'yes' ],
118 ] );
119 $this->add_control( 'link_to', [
120 'label' => __( 'Link To', 'easy-elements' ),
121 'type' => Controls_Manager::SELECT,
122 'default' => 'default',
123 'options' => [
124 'default' => __( 'Home Page', 'easy-elements' ),
125 'none' => __( 'None', 'easy-elements' ),
126 'file' => __( 'Media File', 'easy-elements' ),
127 'custom' => __( 'Custom URL', 'easy-elements' ),
128 ],
129 ] );
130 $this->add_control( 'link', [
131 'label' => __( 'Custom URL', 'easy-elements' ),
132 'type' => Controls_Manager::URL,
133 'dynamic' => [ 'active' => true ],
134 'placeholder' => __( 'https://your-link.com', 'easy-elements' ),
135 'condition' => [ 'link_to' => 'custom' ],
136 'show_label' => false,
137 ] );
138 $this->end_controls_section();
139
140 // Caption Style Section
141 $this->start_controls_section(
142 'section_caption_style',
143 [
144 'label' => __( 'Caption Style', 'easy-elements' ),
145 'tab' => Controls_Manager::TAB_STYLE,
146 'condition' => [ 'caption_source' => 'yes' ],
147 ]
148 );
149
150 $this->add_control(
151 'caption_color',
152 [
153 'label' => __( 'Color', 'easy-elements' ),
154 'type' => Controls_Manager::COLOR,
155 'selectors' => [
156 '{{WRAPPER}} .eel-site-logo .wp-caption-text' => 'color: {{VALUE}};',
157 ],
158 ]
159 );
160
161 $this->add_group_control(
162 Group_Control_Typography::get_type(),
163 [
164 'name' => 'caption_typography',
165 'label' => __( 'Typography', 'easy-elements' ),
166 'selector' => '{{WRAPPER}} .eel-site-logo .wp-caption-text',
167 ]
168 );
169
170 $this->add_group_control(
171 Group_Control_Text_Shadow::get_type(),
172 [
173 'name' => 'caption_text_shadow',
174 'label' => __( 'Text Shadow', 'easy-elements' ),
175 'selector' => '{{WRAPPER}} .eel-site-logo .wp-caption-text',
176 ]
177 );
178
179 $this->add_responsive_control(
180 'caption_margin',
181 [
182 'label' => __( 'Margin', 'easy-elements' ),
183 'type' => Controls_Manager::DIMENSIONS,
184 'size_units' => [ 'px', 'em', '%' ],
185 'selectors' => [
186 '{{WRAPPER}} .eel-site-logo .wp-caption-text' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
187 ],
188 ]
189 );
190
191 $this->end_controls_section();
192
193 // Add Header Edit Button if in Header template
194 if ( function_exists( 'elementor_theme_do_location' ) && elementor_theme_do_location( 'header' ) ) {
195 $this->start_controls_section(
196 'ee_header_edit_section',
197 [
198 'label' => __( 'Header Builder', 'easy-elements' ),
199 ]
200 );
201 $this->add_control(
202 'ee_header_edit_button',
203 [
204 'type' => Controls_Manager::RAW_HTML,
205 'raw' => '<a href="http://localhost:10185/wp-admin/edit.php?post_type=ee-elementor-hf" target="_blank" class="elementor-button elementor-button-success" style="margin:10px 0;display:inline-block;">' . __( 'Edit Header Templates', 'easy-elements' ) . '</a>',
206 'content_classes' => 'ee-header-edit-link',
207 ]
208 );
209 $this->end_controls_section();
210 }
211 }
212
213 protected function get_logo_or_fallback( $settings ) {
214 // Helper to get image URL from attachment ID
215 $get_image_url = function( $id ) {
216 $img = wp_get_attachment_image_src( $id, 'full' );
217 return $img ? $img[0] : false;
218 };
219
220 // 1. Custom logo from widget
221 if ( 'yes' === $settings['site_logo_fallback'] ) {
222 if ( ! empty( $settings['custom_image']['id'] ) ) {
223 if ( $url = $get_image_url( $settings['custom_image']['id'] ) ) {
224 return [ 'type' => 'image', 'url' => $url ];
225 }
226 } elseif ( ! empty( $settings['custom_image']['url'] ) ) {
227 return [ 'type' => 'image', 'url' => $settings['custom_image']['url'] ];
228 }
229 if ( ! empty( $settings['custom_sticky_image']['id'] ) ) {
230 if ( $url = $get_image_url( $settings['custom_sticky_image']['id'] ) ) {
231 return [ 'type' => 'image', 'url' => $url ];
232 }
233 } elseif ( ! empty( $settings['custom_sticky_image']['url'] ) ) {
234 return [ 'type' => 'image', 'url' => $settings['custom_sticky_image']['url'] ];
235 }
236 }
237
238 // 2. Kirki logo (entro_logo)
239 $kirki_logo = null;
240 if ( class_exists( 'Kirki' ) ) {
241 $kirki_logo = Kirki::get_option( 'entro', 'site_logo' );
242 }
243 if ( is_array( $kirki_logo ) && ! empty( $kirki_logo['url'] ) ) {
244 return [ 'type' => 'image', 'url' => $kirki_logo['url'] ];
245 }
246 if ( is_string( $kirki_logo ) && filter_var( $kirki_logo, FILTER_VALIDATE_URL ) ) {
247 return [ 'type' => 'image', 'url' => $kirki_logo ];
248 }
249
250 // 3. WP Site Identity logo
251 if ( $logo_id = get_theme_mod( 'custom_logo' ) ) {
252 if ( $url = $get_image_url( $logo_id ) ) {
253 return [ 'type' => 'image', 'url' => $url ];
254 }
255 }
256
257 // 4. Kirki site title and tagline fallback
258 $kirki_title = null;
259 $kirki_tagline = null;
260 if ( class_exists( 'Kirki' ) ) {
261 $kirki_title = Kirki::get_option( 'entro', 'site_title' );
262 $kirki_tagline = Kirki::get_option( 'entro', 'site_tagline' );
263 }
264 if ( ! empty( $kirki_title ) ) {
265 return [
266 'type' => 'text',
267 'title' => $kirki_title,
268 'tagline' => $kirki_tagline,
269 ];
270 }
271
272 // 5. Site title and tagline fallback
273 return [
274 'type' => 'text',
275 'title' => get_bloginfo( 'name' ),
276 'tagline' => get_bloginfo( 'description' ),
277 ];
278 }
279
280 protected function render() {
281 $settings = $this->get_settings_for_display();
282 $logo_data = $this->get_logo_or_fallback( $settings );
283 $caption = ! empty( $settings['caption_source'] ) && 'yes' === $settings['caption_source'] ? $settings['caption'] : '';
284 $alt_text = esc_attr( get_bloginfo( 'name' ) );
285
286 $this->add_render_attribute( 'wrapper', 'class', 'eel-site-logo' );
287
288 // Add eel-site-logo-added class if logo image is present
289 if ( $logo_data['type'] === 'image' ) {
290 $this->add_render_attribute( 'wrapper', 'class', 'eel-site-logo-added' );
291 }
292
293 // Link setup
294 $link = '';
295 if ( 'file' === $settings['link_to'] && isset( $logo_data['url'] ) ) {
296 $link = $logo_data['url'];
297 } elseif ( 'default' === $settings['link_to'] ) {
298 $link = home_url();
299 } elseif ( 'custom' === $settings['link_to'] && ! empty( $settings['link']['url'] ) ) {
300 $link = $settings['link']['url'];
301 }
302
303 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Safe, output contains trusted HTML attributes.
304 echo '<div ' . $this->get_render_attribute_string( 'wrapper' ) . '>';
305
306 if ( $caption ) {
307 echo '<figure class="wp-caption">';
308 }
309 if ( $link ) {
310 $target = ! empty( $settings['link']['is_external'] ) ? ' target="_blank"' : '';
311 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Safe, output contains trusted HTML attributes.
312 echo '<a href="' . esc_url( $link ) . '"' . $target . '>';
313 }
314 if ( $logo_data['type'] === 'image' ) {
315 $attachment_id = 0;
316 if ( ! empty( $settings['custom_image']['id'] ) ) {
317 $attachment_id = $settings['custom_image']['id'];
318 } elseif ( ! empty( $settings['custom_sticky_image']['id'] ) ) {
319 $attachment_id = $settings['custom_sticky_image']['id'];
320 } else {
321 $attachment_id = attachment_url_to_postid( $logo_data['url'] );
322 }
323 if ( $attachment_id ) {
324 $sticky_logo_id = get_theme_mod( 'sticky_logo' );
325 if ( ! empty( $settings['custom_sticky_image']['id'] ) ) {
326 $sticky_logo_id = $settings['custom_sticky_image']['id'];
327 }
328 $sticky_logo_url = is_numeric( $sticky_logo_id ) ? wp_get_attachment_image_url( $sticky_logo_id, 'full' ) : $sticky_logo_id;
329
330 // Build class string
331 $main_logo_classes = 'eel-main-logo';
332 if ( empty( $sticky_logo_url ) ) {
333 $main_logo_classes .= ' eel-no-sticky';
334 }
335
336 // Output main logo
337 echo wp_get_attachment_image( $attachment_id, 'full', false, [
338 'class' => $main_logo_classes,
339 'alt' => $alt_text,
340 'loading' => 'lazy',
341 'decoding' => 'async',
342 ] );
343
344 // Output sticky logo if available
345 if ( $sticky_logo_url ) {
346 echo '<img class="eel-sticky-logo" src="' . esc_url( $sticky_logo_url ) . '" alt="' . esc_attr( get_bloginfo( 'name' ) ) . '" decoding="async">';
347 }
348 } else {
349 $img_html = '<img src="' . esc_url( $logo_data['url'] ) . '" alt="' . esc_attr( $alt_text ) . '" decoding="async">';
350 echo wp_kses_post( apply_filters( 'easy_elements_site_logo_fallback_img_html', $img_html, $logo_data['url'], $alt_text, $settings ) );
351 }
352 } else {
353 // Show site title and tagline as fallback
354 echo '<div class="eel-site-title-tagline">';
355 echo '<h1 class="eel-site-title">' . esc_html( $logo_data['title'] ) . '</h1>';
356 if ( ! empty( $logo_data['tagline'] ) ) {
357 echo '<p class="eel-site-tagline">' . esc_html( $logo_data['tagline'] ) . '</p>';
358 }
359 echo '</div>';
360 }
361 if ( $link ) {
362 echo '</a>';
363 }
364 if ( $caption ) {
365 echo '<figcaption class="wp-caption-text">' . esc_html( $caption ) . '</figcaption>';
366 echo '</figure>';
367 }
368 echo '</div>';
369 }
370 }
371 ?>
372