PluginProbe ʕ •ᴥ•ʔ
Kubio AI Page Builder / 2.8.6
Kubio AI Page Builder v2.8.6
2.9.1 2.9.0 2.8.6 2.8.5 2.8.4 2.8.3 2.8.2 2.8.1 trunk 1.0.0 1.0.1 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.7.0 1.7.1 1.7.2 1.7.3 1.8.0 1.8.1 1.8.2 1.9.0 2.0.0 2.1.1 2.1.2 2.1.3 2.2.0 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.3.3 2.3.4 2.4.0 2.4.1 2.4.2 2.4.3 2.4.5 2.5.0 2.5.1 2.5.2 2.5.3 2.6.0 2.6.1 2.6.2 2.6.3 2.6.5 2.6.6 2.6.7 2.7.0 2.7.1 2.7.2 2.7.3 2.8.0
kubio / build / block-library / blocks / pagination-numbers / index.php
kubio / build / block-library / blocks / pagination-numbers Last commit date
block.json 3 years ago index.php 1 year ago
index.php
102 lines
1 <?php
2
3 namespace Kubio\Blocks;
4
5 use IlluminateAgnostic\Arr\Support\Arr;
6 use Kubio\Core\Blocks\BlockBase;
7 use Kubio\Core\Registry;
8
9 class PaginationNumbersBlock extends BlockBase {
10 const OUTER = 'outer';
11
12 public function mapPropsToElements() {
13 return array(
14 self::OUTER => array(
15 'innerHTML' => $this->getPageNumbers(),
16 ),
17 );
18 }
19
20 private function getPageNumbers() {
21
22 $pages_data = $this->getPagesData();
23
24 return paginate_links(
25 array(
26 'prev_next' => false,
27 'total' => esc_attr( $pages_data['total'] ),
28 'current' => esc_attr( $pages_data['current'] ),
29 'show_all' => esc_attr( $this->getAttribute( 'show_all', false ) ),
30 )
31 );
32 }
33
34 private function getPagesData() {
35 global $wp_query;
36 $current = 1;
37 $total = 1;
38
39 if ( Arr::get( $this->block_context, 'useMainQuery', false ) ) {
40 $current = get_query_var( 'paged' ) ? (int) get_query_var( 'paged' ) : 1;
41 $total = isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1;
42 } else {
43
44 $query_id = Arr::get( $this->block_context, 'queryId', false );
45 $page_key = $query_id ? 'query-' . $query_id . '-page' : 'query-page';
46 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.MissingUnslash
47 $current = empty( $_GET[ $page_key ] ) ? 1 : filter_var( $_GET[ $page_key ], FILTER_VALIDATE_INT );
48 $total = Arr::get( $this->block_context, 'query.pages', 1 );
49 }
50
51 return array(
52 'total' => $total,
53 'current' => $current,
54 );
55 }
56
57 public function serverSideRender( $wp_block ) {
58 return paginate_links(
59 array(
60 'prev_next' => false,
61 'total' => 12,
62 'current' => 2,
63 'show_all' => $this->getAttribute( 'show_all', false ),
64 )
65 );
66 }
67
68 public function render( $wp_block ) {
69
70 if ( ! $this->shouldRender() && ! $this->isSandboxRender() ) {
71 return '';
72 }
73
74 return parent::render( $wp_block );
75 }
76
77 private function shouldRender() {
78
79 if ( Arr::get( $this->block_context, 'useMainQuery', false ) ) {
80 return $this->shouldRenderMainQueryButton();
81 }
82
83 return $this->shouldRenderCustomQueryButton();
84 }
85
86 private function shouldRenderMainQueryButton() {
87 global $wp_query;
88
89 $total = isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1;
90
91 return $total > 1;
92 }
93
94 private function shouldRenderCustomQueryButton() {
95 $pages = Arr::get( $this->block_context, 'query.pages', 1 );
96
97 return ( $pages > 1 );
98 }
99 }
100
101 Registry::registerBlock( __DIR__, PaginationNumbersBlock::class );
102