StringLimit.php
1.58 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
<?php
namespace AC\Settings\Column;
use AC\Settings;
use AC\View;
class StringLimit extends Settings\Column {
/**
* @var string
*/
private $string_limit;
protected function define_options() {
return [ 'string_limit' => 'word_limit' ];
}
public function create_view() {
$setting = $this->create_element( 'select' )
->set_attribute( 'data-refresh', 'column' )
->set_options( $this->get_limit_options() );
$view = new View( [
'label' => __( 'Text Limit', 'codepress-admin-columns' ),
'tooltip' => __( 'Limit text to a certain number of characters or words', 'codepress-admin-columns' ),
'setting' => $setting,
] );
return $view;
}
private function get_limit_options() {
$options = [
'' => __( 'No limit', 'codepress-admin-columns' ),
'character_limit' => __( 'Character Limit', 'codepress-admin-columns' ),
'word_limit' => __( 'Word Limit', 'codepress-admin-columns' ),
];
return $options;
}
public function get_dependent_settings() {
$setting = [];
switch ( $this->get_string_limit() ) {
case 'character_limit' :
$setting[] = new Settings\Column\CharacterLimit( $this->column );
break;
case 'word_limit' :
$setting[] = new Settings\Column\WordLimit( $this->column );
break;
}
return $setting;
}
/**
* @return string
*/
public function get_string_limit() {
return $this->string_limit;
}
/**
* @param string $string_limit
*
* @return true
*/
public function set_string_limit( $string_limit ) {
$this->string_limit = $string_limit;
return true;
}
}