PluginProbe
King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder / 51.1.84
King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder v51.1.84
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_Post_Navigation / TB_Post_Navigation.php

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

396 lines 11.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Theme Builder Post Navigation 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 * Shows previous/next post navigation.
20 */
21 class TB_Post_Navigation 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-post-navigation';
31 }
32
33 /**
34 * Widget title.
35 *
36 * @return string
37 */
38 public function get_title(): string
39 {
40 return esc_html__('TB - Post Navigation', '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-post-navigation';
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-post-navigation-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-post-navigation-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 ['navigation', 'previous', 'next', 'post', '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_show',
140 [
141 'label' => esc_html__('Show', 'king-addons'),
142 'type' => Controls_Manager::SELECT,
143 'default' => 'both',
144 'options' => [
145 'previous' => esc_html__('Previous Only', 'king-addons'),
146 'next' => esc_html__('Next Only', 'king-addons'),
147 'both' => esc_html__('Both', 'king-addons'),
148 ],
149 ]
150 );
151
152 $this->add_control(
153 'kng_prev_label',
154 [
155 'label' => esc_html__('Previous Label', 'king-addons'),
156 'type' => Controls_Manager::TEXT,
157 'dynamic' => ['active' => true],
158 'default' => esc_html__('Previous', 'king-addons'),
159 ]
160 );
161
162 $this->add_control(
163 'kng_next_label',
164 [
165 'label' => esc_html__('Next Label', 'king-addons'),
166 'type' => Controls_Manager::TEXT,
167 'dynamic' => ['active' => true],
168 'default' => esc_html__('Next', 'king-addons'),
169 ]
170 );
171
172 $this->add_control(
173 'kng_show_titles',
174 [
175 'label' => esc_html__('Show Post Titles', 'king-addons'),
176 'type' => Controls_Manager::SWITCHER,
177 'return_value' => 'yes',
178 'default' => 'yes',
179 ]
180 );
181
182 $this->add_control(
183 'kng_same_tax',
184 [
185 'label' => $is_pro ?
186 esc_html__('Restrict to Same Category', 'king-addons') :
187 sprintf(__('Restrict to Same Category %s', 'king-addons'), '<i class="eicon-pro-icon"></i>'),
188 'type' => Controls_Manager::SWITCHER,
189 'return_value' => 'yes',
190 'default' => '',
191 'classes' => $is_pro ? '' : 'king-addons-pro-control',
192 ]
193 );
194
195 $this->add_control(
196 'kng_layout',
197 [
198 'label' => esc_html__('Layout', 'king-addons'),
199 'type' => Controls_Manager::SELECT,
200 'default' => 'inline',
201 'options' => [
202 'inline' => esc_html__('Inline', 'king-addons'),
203 'columns' => esc_html__('Two Columns', 'king-addons'),
204 'stacked' => esc_html__('Stacked', 'king-addons'),
205 ],
206 ]
207 );
208
209 $this->end_controls_section();
210 }
211
212 /**
213 * Style controls.
214 *
215 * @param bool $is_pro Whether Pro controls are enabled.
216 *
217 * @return void
218 */
219 protected function register_style_controls(bool $is_pro): void
220 {
221 $this->start_controls_section(
222 'kng_style_section',
223 [
224 'label' => esc_html__('Style', 'king-addons'),
225 'tab' => Controls_Manager::TAB_STYLE,
226 ]
227 );
228
229 $this->add_group_control(
230 Group_Control_Typography::get_type(),
231 [
232 'name' => 'kng_label_typography',
233 'label' => esc_html__('Label Typography', 'king-addons'),
234 'selector' => '{{WRAPPER}} .king-addons-tb-post-navigation__label',
235 ]
236 );
237
238 $this->add_group_control(
239 Group_Control_Typography::get_type(),
240 [
241 'name' => 'kng_title_typography',
242 'label' => esc_html__('Title Typography', 'king-addons'),
243 'selector' => '{{WRAPPER}} .king-addons-tb-post-navigation__title',
244 ]
245 );
246
247 $this->add_control(
248 'kng_text_color',
249 [
250 'label' => esc_html__('Text Color', 'king-addons'),
251 'type' => Controls_Manager::COLOR,
252 'selectors' => [
253 '{{WRAPPER}} .king-addons-tb-post-navigation' => 'color: {{VALUE}};',
254 '{{WRAPPER}} .king-addons-tb-post-navigation a' => 'color: {{VALUE}};',
255 ],
256 ]
257 );
258
259 $this->add_control(
260 'kng_text_color_hover',
261 [
262 'label' => esc_html__('Hover Color', 'king-addons'),
263 'type' => Controls_Manager::COLOR,
264 'selectors' => [
265 '{{WRAPPER}} .king-addons-tb-post-navigation a:hover' => 'color: {{VALUE}};',
266 ],
267 ]
268 );
269
270 $this->add_responsive_control(
271 'kng_gap',
272 [
273 'label' => esc_html__('Gap', 'king-addons'),
274 'type' => Controls_Manager::SLIDER,
275 'size_units' => ['px'],
276 'range' => [
277 'px' => ['min' => 0, 'max' => 60],
278 ],
279 'default' => [
280 'size' => 12,
281 'unit' => 'px',
282 ],
283 'selectors' => [
284 '{{WRAPPER}} .king-addons-tb-post-navigation' => 'gap: {{SIZE}}{{UNIT}};',
285 ],
286 ]
287 );
288
289 $this->end_controls_section();
290 }
291
292 /**
293 * Pro upsell.
294 *
295 * @return void
296 */
297 protected function register_pro_notice_controls(): void
298 {
299 if (king_addons_freemius()->can_use_premium_code__premium_only()) {
300 return;
301 }
302
303 Core::renderProFeaturesSection(
304 $this,
305 '',
306 Controls_Manager::RAW_HTML,
307 'tb-post-navigation',
308 [
309 'Restrict navigation to same category',
310 'Arrow icons and advanced layout skins',
311 ]
312 );
313 }
314
315 /**
316 * Render output helper.
317 *
318 * @param array<string, mixed> $settings Widget settings.
319 * @param bool $is_pro Whether Pro is enabled.
320 *
321 * @return void
322 */
323 protected function render_output(array $settings, bool $is_pro): void
324 {
325 $post = get_post();
326 if (!$post instanceof \WP_Post) {
327 return;
328 }
329
330 $same = $is_pro && ('yes' === ($settings['kng_same_tax'] ?? '')) ? true : false;
331 $previous = get_previous_post($same);
332 $next = get_next_post($same);
333
334 $show = $settings['kng_show'] ?? 'both';
335 $items = [];
336
337 if (('previous' === $show || 'both' === $show) && $previous instanceof \WP_Post) {
338 $items[] = $this->build_item(
339 $settings['kng_prev_label'] ?? '',
340 $previous,
341 'prev',
342 $settings
343 );
344 }
345
346 if (('next' === $show || 'both' === $show) && $next instanceof \WP_Post) {
347 $items[] = $this->build_item(
348 $settings['kng_next_label'] ?? '',
349 $next,
350 'next',
351 $settings
352 );
353 }
354
355 if (empty($items)) {
356 return;
357 }
358
359 $layout = $settings['kng_layout'] ?? 'inline';
360 $classes = ['king-addons-tb-post-navigation', 'king-addons-tb-post-navigation--' . $layout];
361
362 echo '<div class="' . esc_attr(implode(' ', $classes)) . '">';
363 foreach ($items as $item) {
364 echo $item; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
365 }
366 echo '</div>';
367 }
368
369 /**
370 * Build item markup.
371 *
372 * @param string $label Label text.
373 * @param \WP_Post $post Target post.
374 * @param string $type Item type prev/next.
375 * @param array $settings Settings.
376 *
377 * @return string
378 */
379 protected function build_item(string $label, \WP_Post $post, string $type, array $settings): string
380 {
381 $title = ('yes' === ($settings['kng_show_titles'] ?? 'yes')) ? get_the_title($post) : '';
382
383 $html = '<div class="king-addons-tb-post-navigation__item king-addons-tb-post-navigation__item--' . esc_attr($type) . '">';
384 $html .= '<a href="' . esc_url(get_permalink($post)) . '">';
385 if ($label) {
386 $html .= '<span class="king-addons-tb-post-navigation__label">' . esc_html($label) . '</span>';
387 }
388 if ($title) {
389 $html .= '<span class="king-addons-tb-post-navigation__title">' . esc_html($title) . '</span>';
390 }
391 $html .= '</a></div>';
392
393 return $html;
394 }
395 }
396