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_Archive_Title / TB_Archive_Title.php

TB_Archive_Title.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_Archive_Title/TB_Archive_Title.php

322 lines 8.5 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 Title 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 the current archive title.
20 */
21 class TB_Archive_Title 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-title';
31 }
32
33 /**
34 * Widget title.
35 *
36 * @return string
37 */
38 public function get_title(): string
39 {
40 return esc_html__('TB - Archive Title', 'king-addons');
41 }
42
43 /**
44 * Widget icon.
45 *
46 * @return string
47 */
48 public function get_icon(): string
49 {
50 return 'eicon-archive-title';
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-title-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-title-script'];
71 }
72
73 /**
74 * Categories.
75 *
76 * @return array<int, string>
77 */
78 public function get_categories(): array
79 {
80 return ['king-addons'];
81 }
82
83 /**
84 * Keywords.
85 *
86 * @return array<int, string>
87 */
88 public function get_keywords(): array
89 {
90 return ['archive', 'title', 'taxonomy', 'search', 'king-addons'];
91 }
92
93 public function get_custom_help_url()
94 {
95 return 'mailto:[email protected]?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_html_tag',
140 [
141 'label' => esc_html__('HTML Tag', 'king-addons'),
142 'type' => Controls_Manager::SELECT,
143 'default' => 'h1',
144 'options' => [
145 'h1' => 'H1',
146 'h2' => 'H2',
147 'h3' => 'H3',
148 'div' => 'div',
149 'span' => 'span',
150 ],
151 ]
152 );
153
154 $this->add_control(
155 'kng_prefix_mode',
156 [
157 'label' => esc_html__('Prefix', 'king-addons'),
158 'type' => Controls_Manager::SELECT,
159 'default' => 'default',
160 'options' => [
161 'default' => esc_html__('Use Default', 'king-addons'),
162 'remove' => esc_html__('Remove Default Prefix', 'king-addons'),
163 'custom' => $is_pro ?
164 esc_html__('Custom Prefix', 'king-addons') :
165 sprintf(__('Custom Prefix %s', 'king-addons'), '<i class="eicon-pro-icon"></i>'),
166 ],
167 ]
168 );
169
170 $this->add_control(
171 'kng_custom_prefix',
172 [
173 'label' => esc_html__('Custom Prefix Text', 'king-addons'),
174 'type' => Controls_Manager::TEXT,
175 'placeholder' => esc_html__('Posts in', 'king-addons'),
176 'condition' => [
177 'kng_prefix_mode' => 'custom',
178 ],
179 'classes' => $is_pro ? '' : 'king-addons-pro-control',
180 ]
181 );
182
183 $this->end_controls_section();
184 }
185
186 /**
187 * Style controls.
188 *
189 * @param bool $is_pro Whether Pro controls are enabled.
190 *
191 * @return void
192 */
193 protected function register_style_controls(bool $is_pro): void
194 {
195 $this->start_controls_section(
196 'kng_style_section',
197 [
198 'label' => esc_html__('Style', 'king-addons'),
199 'tab' => Controls_Manager::TAB_STYLE,
200 ]
201 );
202
203 $this->add_group_control(
204 Group_Control_Typography::get_type(),
205 [
206 'name' => 'kng_typography',
207 'selector' => '{{WRAPPER}} .king-addons-tb-archive-title',
208 ]
209 );
210
211 $this->add_control(
212 'kng_color',
213 [
214 'label' => esc_html__('Color', 'king-addons'),
215 'type' => Controls_Manager::COLOR,
216 'selectors' => [
217 '{{WRAPPER}} .king-addons-tb-archive-title' => 'color: {{VALUE}};',
218 ],
219 ]
220 );
221
222 $this->add_responsive_control(
223 'kng_alignment',
224 [
225 'label' => esc_html__('Alignment', 'king-addons'),
226 'type' => Controls_Manager::CHOOSE,
227 'options' => [
228 'left' => [
229 'title' => esc_html__('Left', 'king-addons'),
230 'icon' => 'eicon-text-align-left',
231 ],
232 'center' => [
233 'title' => esc_html__('Center', 'king-addons'),
234 'icon' => 'eicon-text-align-center',
235 ],
236 'right' => [
237 'title' => esc_html__('Right', 'king-addons'),
238 'icon' => 'eicon-text-align-right',
239 ],
240 ],
241 'selectors' => [
242 '{{WRAPPER}} .king-addons-tb-archive-title' => 'text-align: {{VALUE}};',
243 ],
244 ]
245 );
246
247 $this->add_responsive_control(
248 'kng_margin',
249 [
250 'label' => esc_html__('Margin', 'king-addons'),
251 'type' => Controls_Manager::DIMENSIONS,
252 'size_units' => ['px', 'em', '%'],
253 'selectors' => [
254 '{{WRAPPER}} .king-addons-tb-archive-title' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
255 ],
256 ]
257 );
258
259 $this->end_controls_section();
260 }
261
262 /**
263 * Pro upsell.
264 *
265 * @return void
266 */
267 protected function register_pro_notice_controls(): void
268 {
269 if (king_addons_freemius()->can_use_premium_code__premium_only()) {
270 return;
271 }
272
273 Core::renderProFeaturesSection(
274 $this,
275 '',
276 Controls_Manager::RAW_HTML,
277 'tb-archive-title',
278 [
279 'Custom prefixes per archive type',
280 'Advanced conditional formatting',
281 ]
282 );
283 }
284
285 /**
286 * Render output helper.
287 *
288 * @param array<string, mixed> $settings Settings.
289 * @param bool $is_pro Pro flag.
290 *
291 * @return void
292 */
293 protected function render_output(array $settings, bool $is_pro): void
294 {
295 $tag = isset($settings['kng_html_tag']) ? strtolower((string) $settings['kng_html_tag']) : 'h1';
296 $allowed_tags = ['h1', 'h2', 'h3', 'div', 'span'];
297 if (!in_array($tag, $allowed_tags, true)) {
298 $tag = 'h1';
299 }
300
301 $title = get_the_archive_title();
302 if ('remove' === ($settings['kng_prefix_mode'] ?? 'default')) {
303 $title = preg_replace('/^[^:]+:\\s*/', '', $title);
304 }
305
306 if ('custom' === ($settings['kng_prefix_mode'] ?? 'default') && $is_pro && !empty($settings['kng_custom_prefix'])) {
307 $title = sprintf('%s %s', $settings['kng_custom_prefix'], $title);
308 }
309
310 $title = wp_strip_all_tags((string) $title);
311 if ('' === $title) {
312 return;
313 }
314
315 printf(
316 '<%1$s class="king-addons-tb-archive-title">%2$s</%1$s>',
317 esc_attr($tag),
318 esc_html($title)
319 );
320 }
321 }
322