ChildPages.php
1.76 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
namespace ACP\Column\Post;
use AC;
use ACP\Export;
use ACP\Filtering;
use ACP\Search;
class ChildPages extends AC\Column
implements Filtering\Filterable, Export\Exportable, Search\Searchable {
public function __construct() {
$this->set_type( 'column-child-pages' );
$this->set_label( __( 'Child Pages', 'codepress-admin-columns' ) );
}
public function get_value( $post_id ) {
$titles = [];
$ids = $this->get_raw_value( $post_id );
if ( $ids ) {
foreach ( $ids as $id ) {
$post = get_post( $id );
$titles[] = ac_helper()->html->link( get_edit_post_link( $id ), $post->post_title );
}
}
if ( empty( $titles ) ) {
return $this->get_empty_char();
}
$number_of_items = $this->get_setting( AC\Settings\Column\NumberOfItems::NAME )->get_value();
return $number_of_items ? ac_helper()->html->more( $titles, $number_of_items ) : ac_helper()->string->enumeration_list( $titles, 'and' );
}
public function get_raw_value( $post_id ) {
$ids = get_posts( [
'post_type' => $this->get_post_type(),
'post_parent' => $post_id,
'fields' => 'ids',
'posts_per_page' => -1,
'orderby' => 'menu_order',
'order' => 'ASC',
] );
return $ids;
}
protected function register_settings() {
$this->add_setting( new AC\Settings\Column\NumberOfItems( $this ) );
}
public function is_valid() {
return is_post_type_hierarchical( $this->get_post_type() ) || post_type_supports( $this->get_post_type(), 'page-attributes' );
}
public function filtering() {
return new Filtering\Model\Post\ChildPages( $this );
}
public function export() {
return new Export\Model\Post\ChildPages( $this );
}
public function search() {
return new Search\Comparison\Post\ChildPages( $this->get_post_type() );
}
}