1: <?php
2:
3: /**
4: * HTML textarea property.
5: */
6: class Papi_Property_Text extends Papi_Property {
7:
8: /**
9: * Format the value of the property before it's returned
10: * to WordPress admin or the site.
11: *
12: * @param mixed $value
13: * @param string $slug
14: * @param int $post_id
15: *
16: * @return array
17: */
18: public function format_value( $value, $slug, $post_id ) {
19: if ( ! $this->get_setting( 'allow_html' ) ) {
20: $value = maybe_unserialize( $value );
21:
22: if ( ! is_string( $value ) ) {
23: $value = '';
24: }
25:
26: $value = wp_strip_all_tags( $value );
27: }
28:
29: return $value;
30: }
31:
32: /**
33: * Get default settings.
34: *
35: * @return array
36: */
37: public function get_default_settings() {
38: return [
39: 'allow_html' => false
40: ];
41: }
42:
43: /**
44: * Get value from the database.
45: *
46: * @return string
47: */
48: public function get_value() {
49: return $this->format_value(
50: parent::get_value(),
51: $this->get_slug(),
52: papi_get_post_id()
53: );
54: }
55:
56: /**
57: * Render property html.
58: */
59: public function html() {
60: papi_render_html_tag( 'textarea', [
61: 'class' => 'papi-property-text',
62: 'id' => $this->html_id(),
63: 'name' => $this->html_name(),
64: $this->get_value()
65: ] );
66: }
67: }
68: