Label.php
1.56 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
<?php
namespace AC\Settings\Column;
use AC\Sanitize\Kses;
use AC\Settings;
use AC\View;
class Label extends Settings\Column {
/**
* @var string
*/
private $label;
protected function define_options() {
return [
'label' => $this->column->get_label(),
'label_type' => 'text',
];
}
public function create_view() {
$setting = $this
->create_element( 'text' )
->set_attribute( 'placeholder', $this->column->get_label() );
$view = new View( [
'label' => __( 'Label', 'codepress-admin-columns' ),
'tooltip' => __( 'This is the name which will appear as the column header.', 'codepress-admin-columns' ),
'setting' => $setting,
] );
$view->set_template( 'settings/setting-label' );
return $view;
}
/**
* Convert site_url() to [cpac_site_url] and back for easy migration
*
* @param string $label
* @param string $action
*
* @return string
*/
private function convert_site_url( $label, $action = 'encode' ) {
return ac_convert_site_url( $label, $action );
}
/**
* @return string
*/
public function get_label() {
return $this->convert_site_url( $this->label, 'decode' );
}
/**
* @param string $label
*/
public function set_label( $label ) {
$sanitize = new Kses();
$this->label = apply_filters( 'ac/column/label', $sanitize->sanitize( $label ), $label );
}
/**
* Encode label with site_url.
* Used when loading the setting from PHP or when a site is migrated to another domain.
* @return string
*/
public function get_encoded_label() {
return $this->convert_site_url( $this->label );
}
}