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

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

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