WordLimit.php
1.36 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
<?php
namespace AC\Settings\Column;
use AC\Settings;
use AC\View;
class WordLimit extends Settings\Column
implements Settings\FormatValue {
/**
* @var int
*/
private $excerpt_length;
protected function set_name() {
$this->name = 'word_limit';
}
protected function define_options() {
return [
'excerpt_length' => 20,
];
}
public function create_view() {
$setting = $this->create_element( 'number' )
->set_attributes( [
'min' => 0,
'step' => 1,
] );
$view = new View( [
'label' => __( 'Word Limit', 'codepress-admin-columns' ),
'tooltip' => __( 'Maximum number of words', 'codepress-admin-columns' ) . '<em>' . __( 'Leave empty for no limit', 'codepress-admin-columns' ) . '</em>',
'setting' => $setting,
] );
return $view;
}
/**
* @return int
*/
public function get_excerpt_length() {
return $this->excerpt_length;
}
/**
* @param int $excerpt_length
*
* @return bool
*/
public function set_excerpt_length( $excerpt_length ) {
$this->excerpt_length = $excerpt_length;
return true;
}
public function format( $value, $original_value ) {
$values = [];
foreach ( (array) $value as $_string ) {
$values[] = ac_helper()->string->trim_words( $_string, $this->get_excerpt_length() );
}
return ac_helper()->html->implode( $values );
}
}