PostFormatIcon.php
1.61 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
74
75
76
77
78
79
80
81
82
83
84
<?php
namespace AC\Settings\Column;
use AC\Settings;
use AC\View;
class PostFormatIcon extends Settings\Column
implements Settings\FormatValue {
/**
* @var bool
*/
private $use_icon;
protected function define_options() {
return [ 'use_icon' => '1' ];
}
public function create_view() {
$setting = $this->create_element( 'radio' )
->set_options( [
'1' => __( 'Yes' ),
'' => __( 'No' ),
] );
$view = new View( [
'label' => __( 'Use an icon?', 'codepress-admin-columns' ),
'tooltip' => __( 'Use an icon instead of text for displaying.', 'codepress-admin-columns' ),
'setting' => $setting,
] );
return $view;
}
/**
* @return int
*/
public function get_use_icon() {
return $this->use_icon;
}
/**
* @param $use_icon
*
* @return bool
*/
public function set_use_icon( $use_icon ) {
$this->use_icon = $use_icon;
return true;
}
private function use_icon() {
return '1' === $this->get_use_icon();
}
/**
* @param $format
* @param int $post_id
*
* @return string
*/
public function format( $format, $post_id ) {
if ( $this->use_icon() ) {
$value = $this->column->get_empty_char();
if ( $format ) {
$value = ac_helper()->html->tooltip( '<span class="ac-post-state-format post-state-format post-format-icon post-format-' . esc_attr( $format ) . '"></span>', get_post_format_string( $format ) );
}
} else {
$value = __( 'Standard', 'codepress-admin-columns' );
if ( $format ) {
$value = esc_html( get_post_format_string( $format ) );
}
}
return $value;
}
}