-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathclass-papi-property-text.php
More file actions
74 lines (64 loc) · 1.36 KB
/
class-papi-property-text.php
File metadata and controls
74 lines (64 loc) · 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
71
72
73
74
<?php
/**
* HTML textarea property.
*/
class Papi_Property_Text extends Papi_Property {
/**
* Format the value of the property before it's returned
* to WordPress admin or the site.
*
* @param mixed $value
* @param string $slug
* @param int $post_id
*
* @return array
*/
public function format_value( $value, $slug, $post_id ) {
if ( ! $this->get_setting( 'allow_html' ) ) {
$value = maybe_unserialize( $value );
if ( ! is_string( $value ) ) {
$value = '';
}
$value = wp_strip_all_tags( $value );
if ( ! papi_is_admin() ) {
$value = $this->get_setting( 'nl2br' ) ? nl2br( $value ) : $value;
}
}
return $value;
}
/**
* Get default settings.
*
* @return array
*/
public function get_default_settings() {
return [
'allow_html' => false,
'nl2br' => true
];
}
/**
* Get value from the database.
*
* @return string
*/
public function get_value() {
$value = $this->format_value(
parent::get_value(),
$this->get_slug(),
papi_get_post_id()
);
return $this->get_setting( 'allow_html' ) ? $value : esc_html( $value );
}
/**
* Render property html.
*/
public function html() {
papi_render_html_tag( 'textarea', [
'class' => 'papi-property-text',
'id' => esc_attr( $this->html_id() ),
'name' => esc_attr( $this->html_name() ),
$this->get_value()
] );
}
}