LastPost.php
1.32 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
<?php
namespace AC\Column\User;
use AC\Column;
use AC\Settings;
/**
* @since 4.2.6
*/
class LastPost extends Column {
public function __construct() {
$this->set_type( 'column-latest_post' );
$this->set_label( __( 'Last Post', 'codepress-admin-columns' ) );
}
public function get_value( $id ) {
$first_post_id = $this->get_raw_value( $id );
if ( ! $first_post_id ) {
return $this->get_empty_char();
}
$post = get_post( $first_post_id );
return $this->get_formatted_value( $post->ID );
}
/**
* @return string
*/
protected function get_related_post_type() {
return $this->get_setting( 'post_type' )->get_value();
}
public function get_raw_value( $user_id ) {
$posts = get_posts( [
'author' => $user_id,
'fields' => 'ids',
'number' => 1,
'post_status' => $this->get_related_post_stati(),
'post_type' => $this->get_related_post_type(),
] );
return empty( $posts ) ? null : $posts[0];
}
/**
* @return array
*/
public function get_related_post_stati() {
return $this->get_setting( Settings\Column\PostStatus::NAME )->get_value();
}
protected function register_settings() {
$this->add_setting( new Settings\Column\PostType( $this ) );
$this->add_setting( new Settings\Column\PostStatus( $this ) );
$this->add_setting( new Settings\Column\Post( $this ) );
}
}