PluginProbe
King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder / 51.1.83
King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder v51.1.83
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 51.1.46 51.1.47 51.1.49 All 37 releases
king-addons / includes / widgets / TB_Archive_Description / TB_Archive_Description.php

TB_Archive_Description.php in King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder 51.1.83, at includes/widgets/TB_Archive_Description/TB_Archive_Description.php

322 lines 8.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Theme Builder Archive Description widget (Free).
4 *
5 * @package King_Addons
6 */
7
8 namespace King_Addons;
9
10 use Elementor\Controls_Manager;
11 use Elementor\Group_Control_Typography;
12 use Elementor\Widget_Base;
13
14 if (!defined('ABSPATH')) {
15 exit;
16 }
17
18 /**
19 * Displays archive description or author bio.
20 */
21 class TB_Archive_Description extends Widget_Base
22 {
23 /**
24 * Widget slug.
25 *
26 * @return string
27 */
28 public function get_name(): string
29 {
30 return 'king-addons-tb-archive-description';
31 }
32
33 /**
34 * Widget title.
35 *
36 * @return string
37 */
38 public function get_title(): string
39 {
40 return esc_html__('TB - Archive Description', 'king-addons');
41 }
42
43 /**
44 * Widget icon.
45 *
46 * @return string
47 */
48 public function get_icon(): string
49 {
50 return 'king-addons-icon king-addons-tb-archive-description';
51 }
52
53 /**
54 * Style dependencies.
55 *
56 * @return array<int, string>
57 */
58 public function get_style_depends(): array
59 {
60 return [KING_ADDONS_ASSETS_UNIQUE_KEY . '-tb-archive-description-style'];
61 }
62
63 /**
64 * Script dependencies.
65 *
66 * @return array<int, string>
67 */
68 public function get_script_depends(): array
69 {
70 return [KING_ADDONS_ASSETS_UNIQUE_KEY . '-tb-archive-description-script'];
71 }
72
73 /**
74 * Categories.
75 *
76 * @return array<int, string>
77 */
78 public function get_categories(): array
79 {
80 return ['king-addons-theme-builder'];
81 }
82
83 /**
84 * Keywords.
85 *
86 * @return array<int, string>
87 */
88 public function get_keywords(): array
89 {
90 return ['archive', 'description', 'bio', 'taxonomy', 'king-addons'];
91 }
92
93 public function get_custom_help_url()
94 {
95 return 'mailto:bug@kingaddons.com?subject=Bug Report - King Addons&body=Please describe the issue';
96 }
97
98 /**
99 * Register controls.
100 *
101 * @return void
102 */
103 public function register_controls(): void
104 {
105 $this->register_content_controls(false);
106 $this->register_style_controls(false);
107 $this->register_pro_notice_controls();
108 }
109
110 /**
111 * Render output.
112 *
113 * @return void
114 */
115 public function render(): void
116 {
117 $settings = $this->get_settings_for_display();
118 $this->render_output($settings, false);
119 }
120
121 /**
122 * Content controls.
123 *
124 * @param bool $is_pro Whether Pro controls are enabled.
125 *
126 * @return void
127 */
128 protected function register_content_controls(bool $is_pro): void
129 {
130 $this->start_controls_section(
131 'kng_content_section',
132 [
133 'label' => KING_ADDONS_ELEMENTOR_ICON . esc_html__('Content', 'king-addons'),
134 'tab' => Controls_Manager::TAB_CONTENT,
135 ]
136 );
137
138 $this->add_control(
139 'kng_trim_words',
140 [
141 'label' => $is_pro ?
142 esc_html__('Trim Length (words)', 'king-addons') :
143 sprintf(__('Trim Length (words) %s', 'king-addons'), '<i class="eicon-pro-icon"></i>'),
144 'type' => Controls_Manager::NUMBER,
145 'min' => 0,
146 'default' => 0,
147 'classes' => $is_pro ? '' : 'king-addons-pro-control',
148 ]
149 );
150
151 $this->add_control(
152 'kng_strip_html',
153 [
154 'label' => esc_html__('Strip HTML', 'king-addons'),
155 'type' => Controls_Manager::SWITCHER,
156 'return_value' => 'yes',
157 'default' => 'yes',
158 ]
159 );
160
161 $this->add_control(
162 'kng_empty_behavior',
163 [
164 'label' => esc_html__('Empty Behavior', 'king-addons'),
165 'type' => Controls_Manager::SELECT,
166 'default' => 'hide',
167 'options' => [
168 'hide' => esc_html__('Hide Widget', 'king-addons'),
169 'placeholder' => $is_pro ?
170 esc_html__('Show Placeholder', 'king-addons') :
171 sprintf(__('Show Placeholder %s', 'king-addons'), '<i class="eicon-pro-icon"></i>'),
172 ],
173 ]
174 );
175
176 $this->add_control(
177 'kng_placeholder_text',
178 [
179 'label' => esc_html__('Placeholder Text', 'king-addons'),
180 'type' => Controls_Manager::TEXT,
181 'dynamic' => ['active' => true],
182 'default' => esc_html__('No description available.', 'king-addons'),
183 'condition' => [
184 'kng_empty_behavior' => 'placeholder',
185 ],
186 'classes' => $is_pro ? '' : 'king-addons-pro-control',
187 ]
188 );
189
190 $this->end_controls_section();
191 }
192
193 /**
194 * Style controls.
195 *
196 * @param bool $is_pro Whether Pro controls are enabled.
197 *
198 * @return void
199 */
200 protected function register_style_controls(bool $is_pro): void
201 {
202 $this->start_controls_section(
203 'kng_style_section',
204 [
205 'label' => esc_html__('Style', 'king-addons'),
206 'tab' => Controls_Manager::TAB_STYLE,
207 ]
208 );
209
210 $this->add_group_control(
211 Group_Control_Typography::get_type(),
212 [
213 'name' => 'kng_typography',
214 'selector' => '{{WRAPPER}} .king-addons-tb-archive-description',
215 ]
216 );
217
218 $this->add_control(
219 'kng_color',
220 [
221 'label' => esc_html__('Color', 'king-addons'),
222 'type' => Controls_Manager::COLOR,
223 'selectors' => [
224 '{{WRAPPER}} .king-addons-tb-archive-description' => 'color: {{VALUE}};',
225 ],
226 ]
227 );
228
229 $this->add_responsive_control(
230 'kng_alignment',
231 [
232 'label' => esc_html__('Alignment', 'king-addons'),
233 'type' => Controls_Manager::CHOOSE,
234 'options' => [
235 'left' => [
236 'title' => esc_html__('Left', 'king-addons'),
237 'icon' => 'eicon-text-align-left',
238 ],
239 'center' => [
240 'title' => esc_html__('Center', 'king-addons'),
241 'icon' => 'eicon-text-align-center',
242 ],
243 'right' => [
244 'title' => esc_html__('Right', 'king-addons'),
245 'icon' => 'eicon-text-align-right',
246 ],
247 ],
248 'selectors' => [
249 '{{WRAPPER}} .king-addons-tb-archive-description' => 'text-align: {{VALUE}};',
250 ],
251 ]
252 );
253
254 $this->add_responsive_control(
255 'kng_margin',
256 [
257 'label' => esc_html__('Margin', 'king-addons'),
258 'type' => Controls_Manager::DIMENSIONS,
259 'size_units' => ['px', 'em', '%'],
260 'selectors' => [
261 '{{WRAPPER}} .king-addons-tb-archive-description' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
262 ],
263 ]
264 );
265
266 $this->end_controls_section();
267 }
268
269 /**
270 * Pro upsell.
271 *
272 * @return void
273 */
274 protected function register_pro_notice_controls(): void
275 {
276 if (king_addons_freemius()->can_use_premium_code__premium_only()) {
277 return;
278 }
279
280 Core::renderProFeaturesSection(
281 $this,
282 '',
283 Controls_Manager::RAW_HTML,
284 'tb-archive-description',
285 [
286 'Trim length and placeholder handling',
287 'Advanced formatting and typography',
288 ]
289 );
290 }
291
292 /**
293 * Render output helper.
294 *
295 * @param array<string, mixed> $settings Settings.
296 * @param bool $is_pro Pro flag.
297 *
298 * @return void
299 */
300 protected function render_output(array $settings, bool $is_pro): void
301 {
302 $description = get_the_archive_description();
303 if ($settings['kng_strip_html'] ?? 'yes') {
304 $description = wp_strip_all_tags((string) $description, true);
305 }
306
307 if ($is_pro && !empty($settings['kng_trim_words'])) {
308 $description = wp_trim_words($description, (int) $settings['kng_trim_words'], '');
309 }
310
311 if (empty($description)) {
312 if ('placeholder' === ($settings['kng_empty_behavior'] ?? 'hide') && $is_pro && !empty($settings['kng_placeholder_text'])) {
313 $description = $settings['kng_placeholder_text'];
314 } else {
315 return;
316 }
317 }
318
319 echo '<div class="king-addons-tb-archive-description">' . wp_kses_post($description) . '</div>';
320 }
321 }
322