class-wpml-tm-post.php
1.27 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
<?php
class WPML_TM_Post extends WPML_TM_Translatable_Element {
/** @var array|null|WP_Post */
private $wp_post;
protected function init( $id ) {
$this->wp_post = get_post( $id );
}
protected function get_type() {
return 'post';
}
protected function get_total_words() {
return $this->word_count_records->get_post_word_count( $this->id )->get_total_words();
}
public function get_type_name( $label = null ) {
$post_type = $this->wp_post->post_type;
$post_type_label = ucfirst( $post_type );
$post_type_object = get_post_type_object( $post_type );
if ( isset( $post_type_object ) ) {
$post_type_object_item = $post_type_object;
$temp_post_type_label = '';
if ( isset( $post_type_object_item->labels->$label ) ) {
$temp_post_type_label = $post_type_object_item->labels->$label;
}
if ( trim( $temp_post_type_label ) == '' ) {
if ( isset( $post_type_object_item->labels->singular_name ) ) {
$temp_post_type_label = $post_type_object_item->labels->singular_name;
} elseif ( $label && $post_type_object_item->labels->name ) {
$temp_post_type_label = $post_type_object_item->labels->name;
}
}
if ( trim( $temp_post_type_label ) != '' ) {
$post_type_label = $temp_post_type_label;
}
}
return $post_type_label;
}
}