PluginProbe
Advanced Custom Fields (ACF®) / 5.9.8
Advanced Custom Fields (ACF®) v5.9.8
6.8.9 6.8.8 6.8.7 6.8.6 6.8.5 6.8.4 6.8.3 6.8.2 6.8.1 5.8.5 5.8.6 5.8.7 5.8.8 5.8.9 5.9.0 5.9.1 5.9.2 5.9.3 5.9.4 5.9.5 5.9.6 5.9.7 5.9.8 5.9.9 6.0.0 All 230 releases
advanced-custom-fields / includes / fields / class-acf-field-message.php
class-acf-field-message.php
198 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if( ! class_exists('acf_field_message') ) :
4
5 class acf_field_message extends acf_field {
6
7
8 /*
9 * __construct
10 *
11 * This function will setup the field type data
12 *
13 * @type function
14 * @date 5/03/2014
15 * @since 5.0.0
16 *
17 * @param n/a
18 * @return n/a
19 */
20
21 function initialize() {
22
23 // vars
24 $this->name = 'message';
25 $this->label = __("Message",'acf');
26 $this->category = 'layout';
27 $this->defaults = array(
28 'message' => '',
29 'esc_html' => 0,
30 'new_lines' => 'wpautop',
31 );
32
33 }
34
35
36 /*
37 * render_field()
38 *
39 * Create the HTML interface for your field
40 *
41 * @param $field - an array holding all the field's data
42 *
43 * @type action
44 * @since 3.6
45 * @date 23/01/13
46 */
47
48 function render_field( $field ) {
49
50 // vars
51 $m = $field['message'];
52
53
54 // wptexturize (improves "quotes")
55 $m = wptexturize( $m );
56
57
58 // esc_html
59 if( $field['esc_html'] ) {
60
61 $m = esc_html( $m );
62
63 }
64
65
66 // new lines
67 if( $field['new_lines'] == 'wpautop' ) {
68
69 $m = wpautop($m);
70
71 } elseif( $field['new_lines'] == 'br' ) {
72
73 $m = nl2br($m);
74
75 }
76
77
78 // return
79 echo acf_esc_html( $m );
80
81 }
82
83
84 /*
85 * render_field_settings()
86 *
87 * Create extra options for your field. This is rendered when editing a field.
88 * The value of $field['name'] can be used (like bellow) to save extra data to the $field
89 *
90 * @param $field - an array holding all the field's data
91 *
92 * @type action
93 * @since 3.6
94 * @date 23/01/13
95 */
96
97 function render_field_settings( $field ) {
98
99 // default_value
100 acf_render_field_setting( $field, array(
101 'label' => __('Message','acf'),
102 'instructions' => '',
103 'type' => 'textarea',
104 'name' => 'message',
105 ));
106
107
108 // formatting
109 acf_render_field_setting( $field, array(
110 'label' => __('New Lines','acf'),
111 'instructions' => __('Controls how new lines are rendered','acf'),
112 'type' => 'select',
113 'name' => 'new_lines',
114 'choices' => array(
115 'wpautop' => __("Automatically add paragraphs",'acf'),
116 'br' => __("Automatically add &lt;br&gt;",'acf'),
117 '' => __("No Formatting",'acf')
118 )
119 ));
120
121
122 // HTML
123 acf_render_field_setting( $field, array(
124 'label' => __('Escape HTML','acf'),
125 'instructions' => __('Allow HTML markup to display as visible text instead of rendering','acf'),
126 'name' => 'esc_html',
127 'type' => 'true_false',
128 'ui' => 1,
129 ));
130
131 }
132
133
134 /*
135 * translate_field
136 *
137 * This function will translate field settings
138 *
139 * @type function
140 * @date 8/03/2016
141 * @since 5.3.2
142 *
143 * @param $field (array)
144 * @return $field
145 */
146
147 function translate_field( $field ) {
148
149 // translate
150 $field['message'] = acf_translate( $field['message'] );
151
152
153 // return
154 return $field;
155
156 }
157
158
159 /*
160 * load_field()
161 *
162 * This filter is appied to the $field after it is loaded from the database
163 *
164 * @type filter
165 * @since 3.6
166 * @date 23/01/13
167 *
168 * @param $field - the field array holding all the field options
169 *
170 * @return $field - the field array holding all the field options
171 */
172 function load_field( $field ) {
173
174 // remove name to avoid caching issue
175 $field['name'] = '';
176
177 // remove instructions
178 $field['instructions'] = '';
179
180 // remove required to avoid JS issues
181 $field['required'] = 0;
182
183 // set value other than 'null' to avoid ACF loading / caching issue
184 $field['value'] = false;
185
186 // return
187 return $field;
188 }
189
190 }
191
192
193 // initialize
194 acf_register_field_type( 'acf_field_message' );
195
196 endif; // class_exists check
197
198 ?>