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