PluginProbe ʕ •ᴥ•ʔ
Kubio AI Page Builder / 2.8.6
Kubio AI Page Builder v2.8.6
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 / query-pagination / index.php
kubio / build / block-library / blocks / query-pagination Last commit date
block.json 4 years ago index.php 4 years ago
index.php
69 lines
1 <?php
2
3 namespace Kubio\Blocks;
4
5 use IlluminateAgnostic\Arr\Support\Arr;
6 use Kubio\Core\Registry;
7
8 class QueryPaginationBlock extends RowBlock {
9
10
11 /**
12 * Render block only if the query has more pages
13 *
14 * @param mixed $wp_block
15 *
16 * @return string
17 */
18 public function render( $wp_block ) {
19
20 if ( $this->queryHasPages() || $this->isSandboxRender() ) {
21 return parent::render( $wp_block );
22 }
23
24 return '';
25 }
26
27 /**
28 * Check if query has more than one page
29 * @return bool
30 */
31 private function queryHasPages() {
32
33 global $wp_query;
34 $use_main_query = Arr::get( $this->block_context, 'useMainQuery', false );
35
36 if ( empty( $this->block_context ) || $use_main_query ) {
37 /**
38 * Global WordPress query
39 * @var \WP_Query $wp_query
40 */
41
42 if ( $wp_query->is_singular() ) {
43 $prev_post = get_adjacent_post();
44 $next_post = get_adjacent_post( false, '', false );
45
46 return ( $prev_post instanceof \WP_Post || $next_post instanceof \WP_Post );
47 }
48
49 global $wp_query;
50 $total = isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1;
51
52 return ( $total > 1 );
53
54 }
55
56 return Arr::get( $this->block_context, 'query.pages', 1 ) > 1;
57 }
58 }
59
60
61 Registry::registerBlock(
62 __DIR__,
63 QueryPaginationBlock::class,
64 array(
65 'metadata' => '../row/block.json',
66 'metadata_mixins' => array( './block.json' ),
67 )
68 );
69