Comment.php
1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
namespace ACP\Helper\Select\Entities;
use AC;
use ACP\Helper\Select\Value;
use WP_Comment_Query;
class Comment extends AC\Helper\Select\Entities
implements AC\Helper\Select\Paginated {
/**
* @var WP_Comment_Query
*/
protected $query;
/**
* @param array $args
* @param AC\Helper\Select\Value $value
*/
public function __construct( array $args = [], AC\Helper\Select\Value $value = null ) {
if ( null === $value ) {
$value = new Value\Comment();
}
$args = array_merge( [
'number' => 30,
'fields' => 'ID',
'orderby' => 'comment_date_gmt',
'paged' => 1,
'search' => null,
'no_found_rows' => false,
], $args );
$args['offset'] = ( $args['paged'] - 1 ) * $args['number'];
$this->query = new WP_Comment_Query( $args );
parent::__construct( $this->query->get_comments(), $value );
}
public function get_total_pages() {
return $this->query->max_num_pages;
}
public function get_page() {
return $this->query->query_vars['paged'];
}
public function is_last_page() {
return $this->get_total_pages() <= $this->get_page();
}
}