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_Pagination / TB_Archive_Pagination.php

TB_Archive_Pagination.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_Pagination/TB_Archive_Pagination.php

332 lines 8.9 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 Pagination 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 * Outputs pagination for the current archive query.
20 */
21 class TB_Archive_Pagination 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-pagination';
31 }
32
33 /**
34 * Widget title.
35 *
36 * @return string
37 */
38 public function get_title(): string
39 {
40 return esc_html__('TB - Archive Pagination', 'king-addons');
41 }
42
43 /**
44 * Widget icon.
45 *
46 * @return string
47 */
48 public function get_icon(): string
49 {
50 return 'eicon-pagination';
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-pagination-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-pagination-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 ['pagination', 'archive', 'navigation', '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_type',
140 [
141 'label' => esc_html__('Type', 'king-addons'),
142 'type' => Controls_Manager::SELECT,
143 'default' => 'numbers',
144 'options' => [
145 'numbers' => esc_html__('Numbers', 'king-addons'),
146 'prev_next' => esc_html__('Previous/Next', 'king-addons'),
147 'numbers_prev_next' => esc_html__('Numbers + Prev/Next', '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_first_last',
172 [
173 'label' => $is_pro ?
174 esc_html__('Show First/Last', 'king-addons') :
175 sprintf(__('Show First/Last %s', 'king-addons'), '<i class="eicon-pro-icon"></i>'),
176 'type' => Controls_Manager::SWITCHER,
177 'return_value' => 'yes',
178 'default' => '',
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-pagination',
208 ]
209 );
210
211 $this->add_control(
212 'kng_color',
213 [
214 'label' => esc_html__('Text Color', 'king-addons'),
215 'type' => Controls_Manager::COLOR,
216 'selectors' => [
217 '{{WRAPPER}} .king-addons-tb-archive-pagination a, {{WRAPPER}} .king-addons-tb-archive-pagination span' => 'color: {{VALUE}};',
218 ],
219 ]
220 );
221
222 $this->add_control(
223 'kng_active_color',
224 [
225 'label' => esc_html__('Active Color', 'king-addons'),
226 'type' => Controls_Manager::COLOR,
227 'selectors' => [
228 '{{WRAPPER}} .king-addons-tb-archive-pagination .current' => 'color: {{VALUE}};',
229 ],
230 ]
231 );
232
233 $this->add_responsive_control(
234 'kng_alignment',
235 [
236 'label' => esc_html__('Alignment', 'king-addons'),
237 'type' => Controls_Manager::CHOOSE,
238 'options' => [
239 'left' => [
240 'title' => esc_html__('Left', 'king-addons'),
241 'icon' => 'eicon-text-align-left',
242 ],
243 'center' => [
244 'title' => esc_html__('Center', 'king-addons'),
245 'icon' => 'eicon-text-align-center',
246 ],
247 'right' => [
248 'title' => esc_html__('Right', 'king-addons'),
249 'icon' => 'eicon-text-align-right',
250 ],
251 ],
252 'selectors' => [
253 '{{WRAPPER}} .king-addons-tb-archive-pagination' => 'text-align: {{VALUE}};',
254 ],
255 ]
256 );
257
258 $this->end_controls_section();
259 }
260
261 /**
262 * Pro upsell.
263 *
264 * @return void
265 */
266 protected function register_pro_notice_controls(): void
267 {
268 if (king_addons_freemius()->can_use_premium_code__premium_only()) {
269 return;
270 }
271
272 Core::renderProFeaturesSection(
273 $this,
274 '',
275 Controls_Manager::RAW_HTML,
276 'tb-archive-pagination',
277 [
278 'First/last page links',
279 'Additional skins and hover states',
280 ]
281 );
282 }
283
284 /**
285 * Render output helper.
286 *
287 * @param array<string, mixed> $settings Settings.
288 * @param bool $is_pro Pro flag.
289 *
290 * @return void
291 */
292 protected function render_output(array $settings, bool $is_pro): void
293 {
294 global $wp_query;
295 if (!$wp_query instanceof \WP_Query || $wp_query->max_num_pages <= 1) {
296 return;
297 }
298
299 $type = $settings['kng_type'] ?? 'numbers';
300 $links = paginate_links(
301 [
302 'type' => 'array',
303 'mid_size' => 1,
304 'prev_next' => in_array($type, ['prev_next', 'numbers_prev_next'], true),
305 'prev_text' => esc_html($settings['kng_prev_label'] ?? ''),
306 'next_text' => esc_html($settings['kng_next_label'] ?? ''),
307 ]
308 );
309
310 if (empty($links)) {
311 return;
312 }
313
314 $show_first_last = $is_pro && ('yes' === ($settings['kng_show_first_last'] ?? ''));
315 $current = max(1, get_query_var('paged'));
316 $max = (int) $wp_query->max_num_pages;
317
318 if ($show_first_last && $current > 1) {
319 array_unshift($links, '<a class="page-numbers" href="' . esc_url(get_pagenum_link(1)) . '">&laquo;</a>');
320 }
321 if ($show_first_last && $current < $max) {
322 $links[] = '<a class="page-numbers" href="' . esc_url(get_pagenum_link($max)) . '">&raquo;</a>';
323 }
324
325 echo '<div class="king-addons-tb-archive-pagination">';
326 foreach ($links as $link) {
327 echo wp_kses_post($link);
328 }
329 echo '</div>';
330 }
331 }
332