PluginProbe
UiCore Elements – Free widgets and templates for Elementor / 1.3.18
UiCore Elements – Free widgets and templates for Elementor v1.3.18
1.3.18 1.3.17 1.3.16 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.2.0 1.2.1 1.2.2 1.2.3 All 42 releases
← All changes | includes/utils/pagination-component.php +305 -233 1.0.3 → 1.3.18 View file →
@@ -1,6 +1,10 @@
1 1 <?php
2 +
2 3 namespace UiCoreElements\Utils;
4 +
5 +use UicoreElements\Helper;
6 +
3 7 use \Elementor\Controls_Manager;
4 8 use \Elementor\Group_Control_Border;
5 9 use \Elementor\Group_Control_Box_Shadow;
6 10 use \Elementor\Group_Control_Typography;
@@ -11,31 +15,28 @@
11 15 * Paginations Trait Component
12 16 *
13 17 */
14 18
15 -trait Pagination_Trait {
19 +trait Pagination_Trait
20 +{
16 21
17 - function pagination_options()
22 + function TRAIT_register_pagination_controls($section = true)
18 23 {
19 - // Set pagination options
20 - $options = [
21 - 'numbers' => esc_html__('Numbers', 'uicore-elements'),
22 - ];
24 + if ($section) {
25 + $this->start_controls_section(
26 + 'section_pagination',
27 + [
28 + 'label' => esc_html__('Pagination', 'uicore-elements'),
29 + ]
30 + );
31 + }
23 32
24 - // if($this->get_settings('posts-filter_post_type') !== 'current'){
25 - $options['load_more'] = esc_html__('Load More', 'uicore-elements');
26 - // }
27 -
28 - return $options;
29 - }
30 - function TRAIT_register_pagination_controls()
31 - {
32 33 $this->add_control(
33 34 'pagination',
34 35 [
35 - 'label' => __( 'Pagination', 'uicore-elements' ),
36 + 'label' => __('Pagination', 'uicore-elements'),
36 37 'type' => Controls_Manager::SWITCHER,
37 - 'default'=> 'no',
38 + 'default' => 'no',
38 39 'render_type' => 'template',
39 40 ]
40 41 );
41 42 $this->add_control(
@@ -43,9 +44,12 @@
43 44 [
44 45 'label' => esc_html__('Pagination Type', 'uicore-elements'),
45 46 'type' => Controls_Manager::SELECT,
46 47 'default' => 'numbers',
47 - 'options' => $this->pagination_options(),
48 + 'options' => [
49 + 'numbers' => esc_html__('Numbers', 'uicore-elements'),
50 + 'load_more' => esc_html__('Load More', 'uicore-elements'),
51 + ],
48 52 'frontend_available' => true,
49 53 'condition' => [
50 54 'pagination' => 'yes',
51 55 ],
@@ -50,17 +54,49 @@
50 54 'pagination' => 'yes',
51 55 ],
52 56 ]
53 57 );
58 + $this->add_control(
59 + 'load_more_qty',
60 + [
61 + 'label' => esc_html__('Posts per Load', 'uicore-elements'),
62 + 'type' => Controls_Manager::SLIDER,
63 + 'range' => [
64 + 'px' => [
65 + 'min' => -1,
66 + 'max' => 100,
67 + ],
68 + ],
69 + 'condition' => array(
70 + 'pagination_type' => 'load_more',
71 + ),
72 + ]
73 + );
74 +
75 + if ($section) {
76 + $this->end_controls_section();
77 + }
54 78 }
79 + function TRAIT_register_pagination_style_controls($section = true)
80 + {
81 + if ($section) {
82 + $this->start_controls_section(
83 + 'section_style_pagination',
84 + [
85 + 'label' => __('Pagination Style', 'uicore-elements'),
86 + 'tab' => Controls_Manager::TAB_STYLE,
87 + 'condition' => [
88 + 'pagination' => 'yes',
89 + ],
90 + ]
91 + );
92 + }
55 93
56 - function TRAIT_register_pagination_style_controls()
57 - {
58 94 $this->add_group_control(
59 95 Group_Control_Typography::get_type(),
60 96 [
61 97 'name' => 'pagination_typography',
62 - 'label' => esc_html__( 'Typography', 'uicore-elements' ),
98 + 'label' => esc_html__('Typography', 'uicore-elements'),
63 99 'selector' => '{{WRAPPER}} .uicore-page-item, {{WRAPPER}} .ui-e-load-more',
64 100 ]
65 101 );
66 102 $this->add_responsive_control(
@@ -65,11 +101,11 @@
65 101 );
66 102 $this->add_responsive_control(
67 103 'icon_size',
68 104 [
69 - 'label' => __( 'Previous/Next Icon Size', 'uicore-elements' ),
105 + 'label' => __('Previous/Next Icon Size', 'uicore-elements'),
70 106 'type' => Controls_Manager::SLIDER,
71 - 'size_units' => [ 'px' ],
107 + 'size_units' => ['px'],
72 108 'range' => [
73 109 'px' => [
74 110 'min' => 0,
75 111 'max' => 30,
@@ -91,11 +127,11 @@
91 127 );
92 128 $this->add_responsive_control(
93 129 'pagination_top',
94 130 [
95 - 'label' => __( 'Pagination Top Space', 'uicore-elements' ),
131 + 'label' => __('Pagination Top Space', 'uicore-elements'),
96 132 'type' => Controls_Manager::SLIDER,
97 - 'size_units' => [ 'px' ],
133 + 'size_units' => ['px'],
98 134 'range' => [
99 135 'px' => [
100 136 'min' => 0,
101 137 'max' => 500,
@@ -114,17 +150,17 @@
114 150 );
115 151 $this->add_control(
116 152 'pagination_align',
117 153 [
118 - 'label' => esc_html__( 'Pagination Alignment', 'uicore-elements' ),
154 + 'label' => esc_html__('Pagination Alignment', 'uicore-elements'),
119 155 'type' => Controls_Manager::CHOOSE,
120 156 'options' => [
121 157 'start' => [
122 - 'title' => esc_html__( 'Left', 'uicore-elements' ),
158 + 'title' => esc_html__('Left', 'uicore-elements'),
123 159 'icon' => 'eicon-text-align-left',
124 160 ],
125 161 'center' => [
126 - 'title' => esc_html__( 'Center', 'uicore-elements' ),
162 + 'title' => esc_html__('Center', 'uicore-elements'),
127 163 'icon' => 'eicon-text-align-center',
128 164 ],
129 165 ],
130 166 'selectors' => [
@@ -136,11 +172,11 @@
136 172 // Number Specific
137 173 $this->add_control(
138 174 'pagination_padding',
139 175 [
140 - 'label' => __( 'Items Padding', 'uicore-elements' ),
176 + 'label' => __('Items Padding', 'uicore-elements'),
141 177 'type' => Controls_Manager::SLIDER,
142 - 'size_units' => [ 'em' ],
178 + 'size_units' => ['em'],
143 179 'range' => [
144 180 'em' => [
145 181 'min' => 0,
146 182 'max' => 3,
@@ -161,11 +197,11 @@
161 197 );
162 198 $this->add_control(
163 199 'pagination_gap',
164 200 [
165 - 'label' => __( 'Items Gap', 'uicore-elements' ),
201 + 'label' => __('Items Gap', 'uicore-elements'),
166 202 'type' => Controls_Manager::SLIDER,
167 - 'size_units' => [ 'em' ],
203 + 'size_units' => ['em'],
168 204 'range' => [
169 205 'em' => [
170 206 'min' => 0,
171 207 'max' => 3,
@@ -186,11 +222,11 @@
186 222 );
187 223 $this->add_control(
188 224 'pagination_radius',
189 225 [
190 - 'label' => __( 'Items Border Radius', 'uicore-elements' ),
226 + 'label' => __('Items Border Radius', 'uicore-elements'),
191 227 'type' => Controls_Manager::SLIDER,
192 - 'size_units' => [ 'em' ],
228 + 'size_units' => ['em'],
193 229 'range' => [
194 230 'em' => [
195 231 'min' => 0,
196 232 'max' => 3,
@@ -212,11 +248,11 @@
212 248 // Load More Specific
213 249 $this->add_control(
214 250 'load_more_padding',
215 251 [
216 - 'label' => esc_html__( 'Button Padding', 'uicore-elements' ),
252 + 'label' => esc_html__('Button Padding', 'uicore-elements'),
217 253 'type' => Controls_Manager::DIMENSIONS,
218 - 'size_units' => [ 'px', '%', 'em'],
254 + 'size_units' => ['px', '%', 'em'],
219 255 'selectors' => [
220 256 '{{WRAPPER}} .ui-e-load-more' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
221 257 ],
222 258 'condition' => array(
@@ -226,11 +262,11 @@
226 262 );
227 263 $this->add_control(
228 264 'load_more_radius',
229 265 [
230 - 'label' => esc_html__( 'Button Radius', 'uicore-elements' ),
266 + 'label' => esc_html__('Button Radius', 'uicore-elements'),
231 267 'type' => Controls_Manager::DIMENSIONS,
232 - 'size_units' => [ 'px', '%', 'em'],
268 + 'size_units' => ['px', '%', 'em'],
233 269 'selectors' => [
234 270 '{{WRAPPER}} .ui-e-load-more' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
235 271 ],
236 272 'condition' => array(
@@ -239,179 +275,206 @@
239 275 ]
240 276 );
241 277 // General Again
242 278 $this->start_controls_tabs(
243 - 'pagination_item', [
279 + 'pagination_item',
280 + [
244 281 'condition' => [
245 282 'pagination' => 'yes',
246 283 ],
247 284 ]
248 285 );
249 - $this->start_controls_tab(
250 - 'pagination_normal_tab',
251 - [
252 - 'label' => esc_html__( 'Normal', 'plugin-name' ),
286 + $this->start_controls_tab(
287 + 'pagination_normal_tab',
288 + [
289 + 'label' => esc_html__('Normal', 'uicore-elements'),
290 + ]
291 + );
292 + $this->add_control(
293 + 'pagination_bg',
294 + [
295 + 'label' => esc_html__('Background', 'uicore-elements'),
296 + 'type' => Controls_Manager::COLOR,
297 + 'default' => '',
298 + 'selectors' => [
299 + '{{WRAPPER}} .uicore-pagination li' => 'background: {{VALUE}};',
300 + '{{WRAPPER}} .ui-e-load-more' => 'background: {{VALUE}};',
301 + ],
302 + ]
303 + );
304 + $this->add_control(
305 + 'pagination_color',
306 + [
307 + 'label' => esc_html__('Color', 'uicore-elements'),
308 + 'type' => Controls_Manager::COLOR,
309 + 'default' => '',
310 + 'selectors' => [
311 + '{{WRAPPER}} .uicore-pagination li a' => 'color: {{VALUE}};',
312 + '{{WRAPPER}} .uicore-pagination svg' => 'fill: {{VALUE}};',
313 + '{{WRAPPER}} .ui-e-load-more' => 'color: {{VALUE}};',
314 + ],
315 + ]
316 + );
317 + $this->add_group_control(
318 + Group_Control_Border::get_type(),
319 + [
320 + 'name' => 'pagination_border',
321 + 'selector' => '{{WRAPPER}} .uicore-pagination ul li, {{WRAPPER}} .ui-e-load-more',
322 + 'separator' => 'before',
323 + ]
324 + );
325 + $this->add_group_control(
326 + Group_Control_Box_Shadow::get_type(),
327 + [
328 + 'name' => 'pagination_shadow',
329 + 'selector' => '{{WRAPPER}} .uicore-pagination ul li, {{WRAPPER}} .ui-e-load-more',
330 + ]
331 + );
332 + $this->end_controls_tab();
333 +
334 + $this->start_controls_tab(
335 + 'pagination_hover_tab',
336 + [
337 + 'label' => esc_html__('Hover', 'uicore-elements'),
338 + ]
339 + );
340 + $this->add_control(
341 + 'pagination_hover_bg',
342 + [
343 + 'label' => esc_html__('Background', 'uicore-elements'),
344 + 'type' => Controls_Manager::COLOR,
345 + 'default' => '',
346 + 'selectors' => [
347 + '{{WRAPPER}} .uicore-pagination ul li:hover:not(.uicore-active)' => 'background: {{VALUE}};',
348 + '{{WRAPPER}} .ui-e-load-more:hover' => 'background: {{VALUE}};',
349 + ],
350 + ]
351 + );
352 + $this->add_control(
353 + 'pagination_hover_color',
354 + [
355 + 'label' => esc_html__('Color', 'uicore-elements'),
356 + 'type' => Controls_Manager::COLOR,
357 + 'default' => '',
358 + 'selectors' => [
359 + '{{WRAPPER}} .uicore-pagination li:hover:not(.uicore-active) a' => 'color: {{VALUE}};',
360 + '{{WRAPPER}} .uicore-pagination li:hover:not(.uicore-active) svg' => 'fill: {{VALUE}};',
361 + '{{WRAPPER}} .ui-e-load-more:hover' => 'color: {{VALUE}};',
362 + ],
363 + ]
364 + );
365 + $this->add_group_control(
366 + Group_Control_Border::get_type(),
367 + [
368 + 'name' => 'pagination_border_hover',
369 + 'selector' => '{{WRAPPER}} .uicore-pagination ul li:hover:not(.uicore-active), {{WRAPPER}} .ui-e-load-more:hover',
370 + 'separator' => 'before',
371 + ]
372 + );
373 + $this->add_group_control(
374 + Group_Control_Box_Shadow::get_type(),
375 + [
376 + 'name' => 'pagination_shadow_hover',
377 + 'selector' => '{{WRAPPER}} .uicore-pagination ul li:hover:not(.uicore-active), {{WRAPPER}} .ui-e-load-more:hover',
378 + ]
379 + );
380 + $this->end_controls_tab();
381 + // Number specific
382 + $this->start_controls_tab(
383 + 'pagination_active_tab',
384 + [
385 + 'label' => esc_html__('Active', 'uicore-elements'),
386 + 'condition' => [
387 + 'pagination_type' => 'numbers',
253 388 ]
254 - );
255 - $this->add_control(
256 - 'pagination_bg',
257 - [
258 - 'label' => esc_html__( 'Background', 'uicore-elements' ),
259 - 'type' => Controls_Manager::COLOR,
260 - 'default' => '',
261 - 'selectors' => [
262 - '{{WRAPPER}} .uicore-pagination li' => 'background: {{VALUE}};',
263 - '{{WRAPPER}} .ui-e-load-more' => 'background: {{VALUE}};',
264 - ],
265 - ]
266 - );
267 - $this->add_control(
268 - 'pagination_color',
269 - [
270 - 'label' => esc_html__( 'Color', 'uicore-elements' ),
271 - 'type' => Controls_Manager::COLOR,
272 - 'default' => '',
273 - 'selectors' => [
274 - '{{WRAPPER}} .uicore-pagination li a' => 'color: {{VALUE}};',
275 - '{{WRAPPER}} .uicore-pagination svg' => 'fill: {{VALUE}};',
276 - '{{WRAPPER}} .ui-e-load-more' => 'color: {{VALUE}};',
277 - ],
278 - ]
279 - );
280 - $this->add_group_control(
281 - Group_Control_Border::get_type(),
282 - [
283 - 'name' => 'pagination_border',
284 - 'selector' => '{{WRAPPER}} .uicore-pagination ul li, {{WRAPPER}} .ui-e-load-more',
285 - 'separator' => 'before',
286 - ]
287 - );
288 - $this->add_group_control(
289 - Group_Control_Box_Shadow::get_type(),
290 - [
291 - 'name' => 'pagination_shadow',
292 - 'selector' => '{{WRAPPER}} .uicore-pagination ul li, {{WRAPPER}} .ui-e-load-more',
293 - ]
294 - );
295 - $this->end_controls_tab();
296 -
297 - $this->start_controls_tab(
298 - 'pagination_hover_tab',
299 - [
300 - 'label' => esc_html__( 'Hover', 'plugin-name' ),
389 + ]
390 + );
391 + $this->add_control(
392 + 'pagination_active_bg',
393 + [
394 + 'label' => esc_html__('Background', 'uicore-elements'),
395 + 'type' => Controls_Manager::COLOR,
396 + 'default' => '',
397 + 'selectors' => [
398 + '{{WRAPPER}} .uicore-page-link.current' => 'background: {{VALUE}};',
399 + ],
400 + 'condition' => [
401 + 'pagination_type' => 'numbers',
301 402 ]
302 - );
303 - $this->add_control(
304 - 'pagination_hover_bg',
305 - [
306 - 'label' => esc_html__( 'Background', 'uicore-elements' ),
307 - 'type' => Controls_Manager::COLOR,
308 - 'default' => '',
309 - 'selectors' => [
310 - '{{WRAPPER}} .uicore-pagination ul li:hover:not(.uicore-active)' => 'background: {{VALUE}};',
311 - '{{WRAPPER}} .ui-e-load-more:hover' => 'background: {{VALUE}};',
312 - ],
313 - ]
314 - );
315 - $this->add_control('pagination_hover_color', [
316 - 'label' => esc_html__( 'Color', 'uicore-elements' ),
317 - 'type' => Controls_Manager::COLOR,
318 - 'default' => '',
319 - 'selectors' => [
320 - '{{WRAPPER}} .uicore-pagination li:hover:not(.uicore-active) a' => 'color: {{VALUE}};',
321 - '{{WRAPPER}} .uicore-pagination li:hover:not(.uicore-active) svg' => 'fill: {{VALUE}};',
322 - '{{WRAPPER}} .ui-e-load-more:hover' => 'color: {{VALUE}};',
323 - ],
324 - ]
325 - );
326 - $this->add_group_control(
327 - Group_Control_Border::get_type(),
328 - [
329 - 'name' => 'pagination_border_hover',
330 - 'selector' => '{{WRAPPER}} .uicore-pagination ul li:hover:not(.uicore-active), {{WRAPPER}} .ui-e-load-more:hover',
331 - 'separator' => 'before',
332 - ]
333 - );
334 - $this->add_group_control(
335 - Group_Control_Box_Shadow::get_type(),
336 - [
337 - 'name' => 'pagination_shadow_hover',
338 - 'selector' => '{{WRAPPER}} .uicore-pagination ul li:hover:not(.uicore-active), {{WRAPPER}} .ui-e-load-more:hover',
339 - ]
340 - );
341 - $this->end_controls_tab();
342 - // Number specific
343 - $this->start_controls_tab(
344 - 'pagination_active_tab',
345 - [
346 - 'label' => esc_html__( 'Active', 'plugin-name' ),
347 - 'condition' => [
348 - 'pagination_type' => 'numbers',
349 - ]
403 + ]
404 + );
405 + $this->add_control(
406 + 'pagination_active_color',
407 + [
408 + 'label' => esc_html__('Color', 'uicore-elements'),
409 + 'type' => Controls_Manager::COLOR,
410 + 'default' => '',
411 + 'selectors' => [
412 + '{{WRAPPER}} .uicore-page-link.current' => 'color: {{VALUE}};',
413 + ],
414 + 'condition' => [
415 + 'pagination_type' => 'numbers',
350 416 ]
351 - );
352 - $this->add_control('pagination_active_bg', [
353 - 'label' => esc_html__( 'Background', 'uicore-elements' ),
354 - 'type' => Controls_Manager::COLOR,
355 - 'default' => '',
356 - 'selectors' => [
357 - '{{WRAPPER}} .uicore-page-link.current' => 'background: {{VALUE}};',
358 - ],
359 - 'condition' => [
360 - 'pagination_type' => 'numbers',
361 - ]
362 - ]
363 - );
364 - $this->add_control('pagination_active_color', [
365 - 'label' => esc_html__( 'Color', 'uicore-elements' ),
366 - 'type' => Controls_Manager::COLOR,
367 - 'default' => '',
368 - 'selectors' => [
369 - '{{WRAPPER}} .uicore-page-link.current' => 'color: {{VALUE}};',
370 - ],
371 - 'condition' => [
372 - 'pagination_type' => 'numbers',
373 - ]
374 - ]
375 - );
376 - $this->add_group_control(
377 - Group_Control_Border::get_type(),
378 - [
379 - 'name' => 'pagination_border_active',
380 - 'selector' => '{{WRAPPER}} .uicore-pagination li.uicore-active',
381 - 'separator' => 'before',
382 - 'condition' => [
383 - 'pagination_type' => 'numbers',
384 - ]
385 - ]
386 - );
387 - $this->add_group_control(
388 - Group_Control_Box_Shadow::get_type(),
389 - [
390 - 'name' => 'pagination_shadow_active',
391 - 'selector' => '{{WRAPPER}} .uicore-pagination li.uicore-active',
392 - 'condition' => [
393 - 'pagination_type' => 'numbers',
394 - ]
395 - ]
396 - );
397 - $this->end_controls_tab();
417 + ]
418 + );
419 + $this->add_group_control(
420 + Group_Control_Border::get_type(),
421 + [
422 + 'name' => 'pagination_border_active',
423 + 'selector' => '{{WRAPPER}} .uicore-pagination li.uicore-active',
424 + 'separator' => 'before',
425 + 'condition' => [
426 + 'pagination_type' => 'numbers',
427 + ]
428 + ]
429 + );
430 + $this->add_group_control(
431 + Group_Control_Box_Shadow::get_type(),
432 + [
433 + 'name' => 'pagination_shadow_active',
434 + 'selector' => '{{WRAPPER}} .uicore-pagination li.uicore-active',
435 + 'condition' => [
436 + 'pagination_type' => 'numbers',
437 + ]
438 + ]
439 + );
440 + $this->end_controls_tab();
398 441
399 442 $this->end_controls_tabs();
443 +
444 + if ($section) {
445 + $this->end_controls_section();
446 + }
400 447 }
401 448
402 449 /**
403 - * sajdnek
450 + * Render pagination numbers.
404 451 *
452 + * @param bool $is_product - If the pagination is for products
405 453 * @param array $args
406 - * @param string $class
407 454 * @author Andrei Voica <[email protected]>
408 455 * @since 1.0.0
409 456 */
410 - function render_numbers($args = [])
457 + function render_numbers($is_product, $args = [])
411 458 {
412 - global $query;
413 459
460 + if ($is_product) {
461 + $query = $this->get_query();
462 +
463 + // Currently we alow users to use number pagination in contexts that shouldn't be used. E.g: in related posts on single product pages
464 + if (!isset($query)) {
465 + return;
466 + }
467 +
468 + $total_items = Helper::get_framework_visible_posts('product');
469 + $total_count = wc_get_products(array_merge($query, ['limit' => -1, 'return' => 'ids'])); // Fetch all products - TODO: -1 is very bad for performance
470 + $total = ceil(count($total_count) / $total_items);
471 + $current_page = max(1, get_query_var('paged'));
472 + } else {
473 + global $query;
474 + }
475 +
476 + // Set pagination args
414 477 $args = wp_parse_args($args, [
415 478 'mid_size' => 2,
416 479 'prev_next' => true,
417 480 'prev_text' => null,
@@ -419,71 +482,80 @@
419 482 'screen_reader_text' => _x('Posts navigation', 'Frontend - Pagination', 'uicore-elements'),
420 483 'type' => 'array',
421 484 'current' => max(1, get_query_var('paged')),
422 485 ]);
423 - if (class_exists('WooCommerce') && isset($query->query['post_type']) && $query->query['post_type'] == 'product' ) {
424 - if ( ! wc_get_loop_prop( 'is_paginated' ) || ! woocommerce_products_will_display() ) {
486 +
487 +
488 + // Build woo pagination args
489 + if ($is_product) {
490 +
491 + if ($total && $total <= 1) {
425 492 return;
426 493 }
427 494
428 - $total = wc_get_loop_prop('total_pages',false);
429 - if ($total && $total <= 1) {
430 - return;
431 - } elseif ($total) {
432 - $args = apply_filters('woocommerce_pagination_args', [
433 - // WPCS: XSS ok.
434 - 'current' => max(1, wc_get_loop_prop('current_page')),
435 - 'total' => $total,
436 - 'prev_text' => '',
437 - 'next_text' => '',
438 - 'type' => 'array',
439 - 'base' => esc_url_raw( add_query_arg( 'product-page', '%#%', false ) ),
440 - 'screen_reader_text' => _x('Products navigation', 'Frontend - Pagination', 'uicore-elements'),
441 - ]);
442 - if ( ! wc_get_loop_prop( 'is_shortcode' ) ) {
443 - $args['format'] = '';
444 - $args['base'] = esc_url_raw( str_replace( 999999999, '%#%', remove_query_arg( 'add-to-cart', get_pagenum_link( 999999999, false ) ) ) );
445 - }
495 + $args = apply_filters('woocommerce_pagination_args', [
496 + // WPCS: XSS ok.
497 + 'current' => $current_page,
498 + 'total' => $total,
499 + 'prev_text' => '',
500 + 'next_text' => '',
501 + 'type' => 'array',
502 + 'base' => esc_url_raw(add_query_arg('product-page', '%#%', false)),
503 + 'screen_reader_text' => _x('Products navigation', 'Frontend - Pagination', 'uicore-elements'),
504 + ]);
505 +
506 + if (! wc_get_loop_prop('is_shortcode')) {
507 + $args['format'] = '';
508 + $args['base'] = esc_url_raw(str_replace(999999999, '%#%', remove_query_arg('add-to-cart', get_pagenum_link(999999999, false))));
446 509 }
447 510 }
511 +
448 512 $links = paginate_links($args);
449 513 $class = 'uicore-pagination';
450 514 $class .= !defined('UICORE_ASSETS') ? ' ui-e-pagination' : '';
515 +
451 516 if (is_array($links) || is_object($links)) { ?>
452 - <nav aria-label="<?php echo $args['screen_reader_text']; ?>" class="<?php echo esc_attr($class);?>">
453 - <ul>
454 - <?php foreach ($links as $key => $link) :
455 - // If next/prev buttons and Uicore Framework is not active, get arrow icon and append it
456 - if ((strpos($link, 'prev') || strpos($link, 'next')) && !defined('UICORE_ASSETS')) {
457 - $svg = \file_get_contents(UICORE_ELEMENTS_ASSETS . '/media/svg/pagination-icon.svg');
458 - $link = str_replace('</a>', $svg . '</a>', $link);
459 - }
517 + <nav aria-label="<?php echo esc_attr($args['screen_reader_text']); ?>" class="<?php echo esc_attr($class); ?>">
518 + <ul>
519 + <?php foreach ($links as $key => $link) :
520 + // If next/prev buttons and Uicore Framework is not active, get arrow icon and append it
521 + if ((strpos($link, 'prev') || strpos($link, 'next')) && !defined('UICORE_ASSETS')) {
522 + $svg = \file_get_contents(UICORE_ELEMENTS_ASSETS . '/media/svg/pagination-icon.svg');
523 + $link = str_replace('</a>', $svg . '</a>', $link);
524 + }
460 525 ?>
461 - <li class="uicore-page-item <?php echo strpos($link, 'current') ? 'uicore-active' : ''; ?>">
462 - <?php echo str_replace('page-numbers', 'uicore-page-link', $link); ?>
463 - </li>
464 - <?php endforeach; ?>
465 - </ul>
466 - </nav>
467 - <?php }
526 + <li class="uicore-page-item <?php echo strpos($link, 'current') ? 'uicore-active' : ''; ?>">
527 + <?php echo wp_kses_post(str_replace('page-numbers', 'uicore-page-link', $link)); ?>
528 + </li>
529 + <?php endforeach; ?>
530 + </ul>
531 + </nav>
532 + <?php }
468 533 }
469 - function render_load_more()
534 + function render_load_more($postID)
470 535 {
471 - // todo: dinamically generate aria-label
536 + // Script may get the current page ID to set as exclusion list on related posts query
472 537 ?>
473 - <nav aria-label="Posts navigation" class="ui-e-pagination">
538 + <nav data-ui-e-current-page="<?php echo esc_attr($postID); ?>" aria-label="Posts navigation" class="ui-e-pagination">
474 539 <button class="ui-e-load-more elementor-button">Load more</button>
475 540 </nav>
476 - <?php
541 +<?php
477 542 }
478 - function TRAIT_render_pagination()
543 +
544 + /**
545 + * Render pagination for post/product widgets
546 + *
547 + * @param array $settings - The settings of the widget
548 + * @param int $postID - The ID of the post or product
549 + * @param bool $is_product - Whether the pagination is for products. Default is false.
550 + */
551 + function TRAIT_render_pagination($settings, $postID, $is_product = false)
479 552 {
480 - if($this->get_settings_for_display('pagination') === 'yes'){
481 -
482 - if($this->get_settings_for_display('pagination_type') === 'load_more'){
483 - $this->render_load_more();
553 + if ($this->is_option('pagination', 'yes')) {
554 + if ($this->is_option('pagination_type', 'load_more')) {
555 + $this->render_load_more($postID);
484 556 } else {
485 - $this->render_numbers();
557 + $this->render_numbers($is_product);
486 558 }
487 559 }
488 560 }
489 561 }