PluginProbe
King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder / 51.1.63
King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder v51.1.63
51.1.86 51.1.84 51.1.85 51.1.83 51.1.82 51.1.81 51.1.79 51.1.78 51.1.77 51.1.76 51.1.74 51.1.75 51.1.65 51.1.64 51.1.63 trunk 51.1.14 51.1.2 51.1.35 51.1.36 51.1.37 51.1.38 51.1.39 51.1.44 51.1.45 All 40 releases
king-addons / includes / widgets / TB_Author_Box / TB_Author_Box.php

TB_Author_Box.php in King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder 51.1.63, at includes/widgets/TB_Author_Box/TB_Author_Box.php

471 lines 14.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Theme Builder Author Box widget (Free).
4 *
5 * @package King_Addons
6 */
7
8 namespace King_Addons;
9
10 use Elementor\Controls_Manager;
11 use Elementor\Group_Control_Border;
12 use Elementor\Group_Control_Box_Shadow;
13 use Elementor\Group_Control_Typography;
14 use Elementor\Repeater;
15 use Elementor\Widget_Base;
16
17 if (!defined('ABSPATH')) {
18 exit;
19 }
20
21 /**
22 * Displays the post author information.
23 */
24 class TB_Author_Box extends Widget_Base
25 {
26 /**
27 * Widget slug.
28 *
29 * @return string
30 */
31 public function get_name(): string
32 {
33 return 'king-addons-tb-author-box';
34 }
35
36 /**
37 * Widget title.
38 *
39 * @return string
40 */
41 public function get_title(): string
42 {
43 return esc_html__('TB - Author Box', 'king-addons');
44 }
45
46 /**
47 * Widget icon.
48 *
49 * @return string
50 */
51 public function get_icon(): string
52 {
53 return 'eicon-person';
54 }
55
56 /**
57 * Style dependencies.
58 *
59 * @return array<int, string>
60 */
61 public function get_style_depends(): array
62 {
63 return [KING_ADDONS_ASSETS_UNIQUE_KEY . '-tb-author-box-style'];
64 }
65
66 /**
67 * Script dependencies.
68 *
69 * @return array<int, string>
70 */
71 public function get_script_depends(): array
72 {
73 return [KING_ADDONS_ASSETS_UNIQUE_KEY . '-tb-author-box-script'];
74 }
75
76 /**
77 * Categories.
78 *
79 * @return array<int, string>
80 */
81 public function get_categories(): array
82 {
83 return ['king-addons'];
84 }
85
86 /**
87 * Keywords.
88 *
89 * @return array<int, string>
90 */
91 public function get_keywords(): array
92 {
93 return ['author', 'bio', 'profile', 'theme builder', 'king-addons'];
94 }
95
96 public function get_custom_help_url()
97 {
98 return 'mailto:[email protected]?subject=Bug Report - King Addons&body=Please describe the issue';
99 }
100
101 /**
102 * Register controls.
103 *
104 * @return void
105 */
106 public function register_controls(): void
107 {
108 $this->register_content_controls(false);
109 $this->register_style_controls(false);
110 $this->register_pro_notice_controls();
111 }
112
113 /**
114 * Render widget output.
115 *
116 * @return void
117 */
118 public function render(): void
119 {
120 $settings = $this->get_settings_for_display();
121 $this->render_output($settings, false);
122 }
123
124 /**
125 * Content controls.
126 *
127 * @param bool $is_pro Whether Pro controls are enabled.
128 *
129 * @return void
130 */
131 protected function register_content_controls(bool $is_pro): void
132 {
133 $this->start_controls_section(
134 'kng_content_section',
135 [
136 'label' => KING_ADDONS_ELEMENTOR_ICON . esc_html__('Content', 'king-addons'),
137 'tab' => Controls_Manager::TAB_CONTENT,
138 ]
139 );
140
141 $this->add_control(
142 'kng_layout',
143 [
144 'label' => esc_html__('Layout', 'king-addons'),
145 'type' => Controls_Manager::SELECT,
146 'default' => 'side',
147 'options' => [
148 'side' => esc_html__('Avatar Left', 'king-addons'),
149 'stacked' => esc_html__('Avatar Top', 'king-addons'),
150 'center' => esc_html__('Centered', 'king-addons'),
151 ],
152 ]
153 );
154
155 $this->add_control(
156 'kng_show_avatar',
157 [
158 'label' => esc_html__('Show Avatar', 'king-addons'),
159 'type' => Controls_Manager::SWITCHER,
160 'return_value' => 'yes',
161 'default' => 'yes',
162 ]
163 );
164
165 $this->add_control(
166 'kng_avatar_size',
167 [
168 'label' => esc_html__('Avatar Size', 'king-addons'),
169 'type' => Controls_Manager::SLIDER,
170 'size_units' => ['px'],
171 'range' => [
172 'px' => ['min' => 30, 'max' => 200],
173 ],
174 'default' => [
175 'size' => 72,
176 'unit' => 'px',
177 ],
178 'condition' => [
179 'kng_show_avatar' => 'yes',
180 ],
181 ]
182 );
183
184 $this->add_control(
185 'kng_link_type',
186 [
187 'label' => esc_html__('Name Link', 'king-addons'),
188 'type' => Controls_Manager::SELECT,
189 'default' => 'archive',
190 'options' => [
191 'none' => esc_html__('None', 'king-addons'),
192 'archive' => esc_html__('Author Archive', 'king-addons'),
193 'custom' => $is_pro ?
194 esc_html__('Custom URL', 'king-addons') :
195 sprintf(__('Custom URL %s', 'king-addons'), '<i class="eicon-pro-icon"></i>'),
196 ],
197 ]
198 );
199
200 $this->add_control(
201 'kng_custom_link',
202 [
203 'label' => esc_html__('Custom URL', 'king-addons'),
204 'type' => Controls_Manager::URL,
205 'placeholder' => 'https://example.com',
206 'condition' => [
207 'kng_link_type' => 'custom',
208 ],
209 'classes' => $is_pro ? '' : 'king-addons-pro-control',
210 ]
211 );
212
213 $this->add_control(
214 'kng_show_website',
215 [
216 'label' => esc_html__('Show Website', 'king-addons'),
217 'type' => Controls_Manager::SWITCHER,
218 'return_value' => 'yes',
219 'default' => 'yes',
220 ]
221 );
222
223 $this->add_control(
224 'kng_show_bio',
225 [
226 'label' => esc_html__('Show Bio', 'king-addons'),
227 'type' => Controls_Manager::SWITCHER,
228 'return_value' => 'yes',
229 'default' => 'yes',
230 ]
231 );
232
233 if ($is_pro) {
234 $repeater = new Repeater();
235 $repeater->add_control(
236 'kng_social_label',
237 [
238 'label' => esc_html__('Label', 'king-addons'),
239 'type' => Controls_Manager::TEXT,
240 'default' => esc_html__('Social', 'king-addons'),
241 ]
242 );
243 $repeater->add_control(
244 'kng_social_url',
245 [
246 'label' => esc_html__('URL', 'king-addons'),
247 'type' => Controls_Manager::URL,
248 'placeholder' => 'https://example.com',
249 ]
250 );
251
252 $this->add_control(
253 'kng_social_links',
254 [
255 'label' => esc_html__('Social Links', 'king-addons'),
256 'type' => Controls_Manager::REPEATER,
257 'fields' => $repeater->get_controls(),
258 'title_field' => '{{ kng_social_label }}',
259 ]
260 );
261 }
262
263 $this->end_controls_section();
264 }
265
266 /**
267 * Style controls.
268 *
269 * @param bool $is_pro Whether Pro controls are enabled.
270 *
271 * @return void
272 */
273 protected function register_style_controls(bool $is_pro): void
274 {
275 $this->start_controls_section(
276 'kng_style_section',
277 [
278 'label' => esc_html__('Box', 'king-addons'),
279 'tab' => Controls_Manager::TAB_STYLE,
280 ]
281 );
282
283 $this->add_control(
284 'kng_box_background',
285 [
286 'label' => esc_html__('Background', 'king-addons'),
287 'type' => Controls_Manager::COLOR,
288 'selectors' => [
289 '{{WRAPPER}} .king-addons-tb-author-box' => 'background-color: {{VALUE}};',
290 ],
291 ]
292 );
293
294 $this->add_group_control(
295 Group_Control_Border::get_type(),
296 [
297 'name' => 'kng_box_border',
298 'selector' => '{{WRAPPER}} .king-addons-tb-author-box',
299 ]
300 );
301
302 $this->add_group_control(
303 Group_Control_Box_Shadow::get_type(),
304 [
305 'name' => 'kng_box_shadow',
306 'selector' => '{{WRAPPER}} .king-addons-tb-author-box',
307 ]
308 );
309
310 $this->add_responsive_control(
311 'kng_box_padding',
312 [
313 'label' => esc_html__('Padding', 'king-addons'),
314 'type' => Controls_Manager::DIMENSIONS,
315 'size_units' => ['px', 'em', '%'],
316 'selectors' => [
317 '{{WRAPPER}} .king-addons-tb-author-box' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
318 ],
319 ]
320 );
321
322 $this->end_controls_section();
323
324 $this->start_controls_section(
325 'kng_content_style',
326 [
327 'label' => esc_html__('Content', 'king-addons'),
328 'tab' => Controls_Manager::TAB_STYLE,
329 ]
330 );
331
332 $this->add_group_control(
333 Group_Control_Typography::get_type(),
334 [
335 'name' => 'kng_name_typography',
336 'label' => esc_html__('Name Typography', 'king-addons'),
337 'selector' => '{{WRAPPER}} .king-addons-tb-author-box__name',
338 ]
339 );
340
341 $this->add_control(
342 'kng_name_color',
343 [
344 'label' => esc_html__('Name Color', 'king-addons'),
345 'type' => Controls_Manager::COLOR,
346 'selectors' => [
347 '{{WRAPPER}} .king-addons-tb-author-box__name' => 'color: {{VALUE}};',
348 '{{WRAPPER}} .king-addons-tb-author-box__name a' => 'color: {{VALUE}};',
349 ],
350 ]
351 );
352
353 $this->add_group_control(
354 Group_Control_Typography::get_type(),
355 [
356 'name' => 'kng_bio_typography',
357 'label' => esc_html__('Bio Typography', 'king-addons'),
358 'selector' => '{{WRAPPER}} .king-addons-tb-author-box__bio, {{WRAPPER}} .king-addons-tb-author-box__website',
359 ]
360 );
361
362 $this->add_control(
363 'kng_text_color',
364 [
365 'label' => esc_html__('Text Color', 'king-addons'),
366 'type' => Controls_Manager::COLOR,
367 'selectors' => [
368 '{{WRAPPER}} .king-addons-tb-author-box__bio' => 'color: {{VALUE}};',
369 '{{WRAPPER}} .king-addons-tb-author-box__website' => 'color: {{VALUE}};',
370 '{{WRAPPER}} .king-addons-tb-author-box__website a' => 'color: {{VALUE}};',
371 ],
372 ]
373 );
374
375 $this->end_controls_section();
376 }
377
378 /**
379 * Pro upsell.
380 *
381 * @return void
382 */
383 protected function register_pro_notice_controls(): void
384 {
385 if (king_addons_freemius()->can_use_premium_code__premium_only()) {
386 return;
387 }
388
389 Core::renderProFeaturesSection(
390 $this,
391 '',
392 Controls_Manager::RAW_HTML,
393 'tb-author-box',
394 [
395 'Custom link target for author name',
396 'Social icons list with custom URLs',
397 'Additional layout and badge styles',
398 ]
399 );
400 }
401
402 /**
403 * Render output helper.
404 *
405 * @param array<string, mixed> $settings Settings.
406 * @param bool $is_pro Whether Pro is enabled.
407 *
408 * @return void
409 */
410 protected function render_output(array $settings, bool $is_pro): void
411 {
412 $post = get_post();
413 if (!$post instanceof \WP_Post) {
414 return;
415 }
416
417 $author_id = (int) $post->post_author;
418 $name = get_the_author_meta('display_name', $author_id);
419 $bio = get_the_author_meta('description', $author_id);
420 $website = get_the_author_meta('user_url', $author_id);
421
422 $layout = $settings['kng_layout'] ?? 'side';
423 $classes = ['king-addons-tb-author-box', 'king-addons-tb-author-box--' . $layout];
424
425 echo '<div class="' . esc_attr(implode(' ', $classes)) . '">';
426
427 if ('yes' === ($settings['kng_show_avatar'] ?? 'yes')) {
428 $size = isset($settings['kng_avatar_size']['size']) ? (int) $settings['kng_avatar_size']['size'] : 72;
429 echo '<div class="king-addons-tb-author-box__avatar">' . get_avatar($author_id, $size) . '</div>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
430 }
431
432 echo '<div class="king-addons-tb-author-box__content">';
433
434 if ($name) {
435 $name_html = esc_html($name);
436 $link_type = $settings['kng_link_type'] ?? 'archive';
437 if ('archive' === $link_type) {
438 $url = get_author_posts_url($author_id);
439 $name_html = '<a href="' . esc_url($url) . '">' . $name_html . '</a>';
440 } elseif ('custom' === $link_type && $is_pro && !empty($settings['kng_custom_link']['url'])) {
441 $url = $settings['kng_custom_link']['url'];
442 $name_html = '<a href="' . esc_url($url) . '">' . $name_html . '</a>';
443 }
444
445 echo '<div class="king-addons-tb-author-box__name">' . $name_html . '</div>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
446 }
447
448 if ('yes' === ($settings['kng_show_bio'] ?? 'yes') && $bio) {
449 echo '<div class="king-addons-tb-author-box__bio">' . esc_html($bio) . '</div>';
450 }
451
452 if ('yes' === ($settings['kng_show_website'] ?? 'yes') && $website) {
453 echo '<div class="king-addons-tb-author-box__website"><a href="' . esc_url($website) . '">' . esc_html($website) . '</a></div>';
454 }
455
456 if ($is_pro && !empty($settings['kng_social_links'])) {
457 echo '<div class="king-addons-tb-author-box__social">';
458 foreach ($settings['kng_social_links'] as $social) {
459 if (empty($social['kng_social_url']['url'])) {
460 continue;
461 }
462 $label = $social['kng_social_label'] ?? esc_html__('Social', 'king-addons');
463 echo '<a class="king-addons-tb-author-box__social-link" href="' . esc_url($social['kng_social_url']['url']) . '">' . esc_html($label) . '</a>';
464 }
465 echo '</div>';
466 }
467
468 echo '</div></div>';
469 }
470 }
471