PluginProbe ʕ •ᴥ•ʔ
Secure Custom Fields / 6.4.1-beta6
Secure Custom Fields v6.4.1-beta6
6.9.5 6.9.4 6.9.3 6.9.2 6.9.1 6.9.0 6.8.9 6.8.7 6.8.8 6.8.6 6.8.4 6.8.5 trunk 6.4.0-beta1 6.4.0-beta2 6.4.1 6.4.1-beta3 6.4.1-beta4 6.4.1-beta5 6.4.1-beta6 6.4.1-beta7 6.4.2 6.5.0 6.5.1 6.5.2 6.5.3 6.5.4 6.5.5 6.5.6 6.5.7 6.6.0 6.7.0 6.7.1 6.8.0 6.8.1 6.8.2 6.8.3
secure-custom-fields / includes / fields / class-acf-field-wysiwyg.php
secure-custom-fields / includes / fields Last commit date
class-acf-field-accordion.php 1 year ago class-acf-field-button-group.php 1 year ago class-acf-field-checkbox.php 1 year ago class-acf-field-clone.php 1 year ago class-acf-field-color_picker.php 1 year ago class-acf-field-date_picker.php 1 year ago class-acf-field-date_time_picker.php 1 year ago class-acf-field-email.php 1 year ago class-acf-field-file.php 1 year ago class-acf-field-flexible-content.php 1 year ago class-acf-field-gallery.php 1 year ago class-acf-field-google-map.php 1 year ago class-acf-field-group.php 1 year ago class-acf-field-icon_picker.php 1 year ago class-acf-field-image.php 1 year ago class-acf-field-link.php 1 year ago class-acf-field-message.php 1 year ago class-acf-field-number.php 1 year ago class-acf-field-oembed.php 1 year ago class-acf-field-output.php 1 year ago class-acf-field-page_link.php 1 year ago class-acf-field-password.php 1 year ago class-acf-field-post_object.php 1 year ago class-acf-field-radio.php 1 year ago class-acf-field-range.php 1 year ago class-acf-field-relationship.php 1 year ago class-acf-field-repeater.php 1 year ago class-acf-field-select.php 1 year ago class-acf-field-separator.php 1 year ago class-acf-field-tab.php 1 year ago class-acf-field-taxonomy.php 1 year ago class-acf-field-text.php 1 year ago class-acf-field-textarea.php 1 year ago class-acf-field-time_picker.php 1 year ago class-acf-field-true_false.php 1 year ago class-acf-field-url.php 1 year ago class-acf-field-user.php 1 year ago class-acf-field-wysiwyg.php 1 year ago class-acf-field.php 1 year ago class-acf-repeater-table.php 1 year ago index.php 1 year ago
class-acf-field-wysiwyg.php
417 lines
1 <?php
2
3 if ( ! class_exists( 'acf_field_wysiwyg' ) ) :
4
5 class acf_field_wysiwyg extends acf_field {
6
7
8 /**
9 * This function will setup the field type data
10 *
11 * @type function
12 * @date 5/03/2014
13 * @since ACF 5.0.0
14 *
15 * @param n/a
16 * @return n/a
17 */
18 function initialize() {
19
20 // vars
21 $this->name = 'wysiwyg';
22 $this->label = __( 'WYSIWYG Editor', 'secure-custom-fields' );
23 $this->category = 'content';
24 $this->description = __( 'Displays the WordPress WYSIWYG editor as seen in Posts and Pages allowing for a rich text-editing experience that also allows for multimedia content.', 'secure-custom-fields' ) . ' ' . __( 'We do not recommend using this field in ACF Blocks.', 'secure-custom-fields' );
25 $this->preview_image = acf_get_url() . '/assets/images/field-type-previews/field-preview-wysiwyg.png';
26 $this->doc_url = 'https://www.advancedcustomfields.com/resources/wysiwyg-editor/';
27 $this->defaults = array(
28 'tabs' => 'all',
29 'toolbar' => 'full',
30 'media_upload' => 1,
31 'default_value' => '',
32 'delay' => 0,
33 );
34 $this->supports = array(
35 'escaping_html' => true,
36 );
37
38 // add acf_the_content filters
39 $this->add_filters();
40
41 // actions
42 add_action( 'acf/enqueue_uploader', array( $this, 'acf_enqueue_uploader' ) );
43 }
44
45
46 /**
47 * This function will add filters to 'acf_the_content'
48 *
49 * @type function
50 * @date 20/09/2016
51 * @since ACF 5.4.0
52 *
53 * @param n/a
54 * @return n/a
55 */
56 function add_filters() {
57
58 // WordPress 5.5 introduced new function for applying image tags.
59 $wp_filter_content_tags = function_exists( 'wp_filter_content_tags' ) ? 'wp_filter_content_tags' : 'wp_make_content_images_responsive';
60
61 // Mimic filters added to "the_content" in "wp-includes/default-filters.php".
62 add_filter( 'acf_the_content', 'capital_P_dangit', 11 );
63 // add_filter( 'acf_the_content', 'do_blocks', 9 ); Not yet supported.
64 add_filter( 'acf_the_content', 'wptexturize' );
65 add_filter( 'acf_the_content', 'convert_smilies', 20 );
66 add_filter( 'acf_the_content', 'wpautop' );
67 add_filter( 'acf_the_content', 'shortcode_unautop' );
68 // add_filter( 'acf_the_content', 'prepend_attachment' ); Causes double image on attachment page.
69 add_filter( 'acf_the_content', $wp_filter_content_tags );
70 add_filter( 'acf_the_content', 'do_shortcode', 11 );
71
72 // Mimic filters added to "the_content" in "wp-includes/class-wp-embed.php"
73 if ( isset( $GLOBALS['wp_embed'] ) ) {
74 add_filter( 'acf_the_content', array( $GLOBALS['wp_embed'], 'run_shortcode' ), 8 );
75 add_filter( 'acf_the_content', array( $GLOBALS['wp_embed'], 'autoembed' ), 8 );
76 }
77 }
78
79
80 /**
81 * This function will return an array of toolbars for the WYSIWYG field
82 *
83 * @type function
84 * @date 18/04/2014
85 * @since ACF 5.0.0
86 *
87 * @param n/a
88 * @return (array)
89 */
90 function get_toolbars() {
91
92 // vars
93 $editor_id = 'acf_content';
94 $toolbars = array();
95
96 // mce buttons (Full)
97 $mce_buttons = array( 'formatselect', 'bold', 'italic', 'bullist', 'numlist', 'blockquote', 'alignleft', 'aligncenter', 'alignright', 'link', 'wp_more', 'spellchecker', 'fullscreen', 'wp_adv' );
98 $mce_buttons_2 = array( 'strikethrough', 'hr', 'forecolor', 'pastetext', 'removeformat', 'charmap', 'outdent', 'indent', 'undo', 'redo', 'wp_help' );
99
100 // mce buttons (Basic)
101 $teeny_mce_buttons = array( 'bold', 'italic', 'underline', 'blockquote', 'strikethrough', 'bullist', 'numlist', 'alignleft', 'aligncenter', 'alignright', 'undo', 'redo', 'link', 'fullscreen' );
102
103 // Full
104 $toolbars['Full'] = array(
105 1 => apply_filters( 'mce_buttons', $mce_buttons, $editor_id ),
106 2 => apply_filters( 'mce_buttons_2', $mce_buttons_2, $editor_id ),
107 3 => apply_filters( 'mce_buttons_3', array(), $editor_id ),
108 4 => apply_filters( 'mce_buttons_4', array(), $editor_id ),
109 );
110
111 // Basic
112 $toolbars['Basic'] = array(
113 1 => apply_filters( 'teeny_mce_buttons', $teeny_mce_buttons, $editor_id ),
114 );
115
116 // Filter for 3rd party
117 $toolbars = apply_filters( 'acf/fields/wysiwyg/toolbars', $toolbars );
118
119 // return
120 return $toolbars;
121 }
122
123
124 /**
125 * Registers toolbars data for the WYSIWYG field.
126 *
127 * @type function
128 * @date 16/12/2015
129 * @since ACF 5.3.2
130 *
131 * @return void
132 */
133 function acf_enqueue_uploader() {
134
135 // vars
136 $data = array();
137 $toolbars = $this->get_toolbars();
138
139 // loop
140 if ( $toolbars ) {
141 foreach ( $toolbars as $label => $rows ) {
142
143 // vars
144 $key = $label;
145 $key = sanitize_title( $key );
146 $key = str_replace( '-', '_', $key );
147
148 // append
149 $data[ $key ] = array();
150
151 if ( $rows ) {
152 foreach ( $rows as $i => $row ) {
153 $data[ $key ][ $i ] = implode( ',', $row );
154 }
155 }
156 }
157 }
158
159 // localize
160 acf_localize_data(
161 array(
162 'toolbars' => $data,
163 )
164 );
165 }
166
167 /**
168 * Create the HTML interface for your field
169 *
170 * @param array $field An array holding all the field's data
171 *
172 * @type action
173 * @since ACF 3.6
174 * @date 23/01/13
175 */
176 function render_field( $field ) {
177
178 // enqueue
179 acf_enqueue_uploader();
180
181 // vars
182 $id = uniqid( 'acf-editor-' );
183 $default_editor = 'html';
184 $show_tabs = true;
185
186 // get height
187 $height = acf_get_user_setting( 'wysiwyg_height', 300 );
188 $height = max( $height, 300 ); // minimum height is 300
189
190 // detect mode
191 if ( ! user_can_richedit() ) {
192 $show_tabs = false;
193 } elseif ( $field['tabs'] == 'visual' ) {
194
195 // case: visual tab only
196 $default_editor = 'tinymce';
197 $show_tabs = false;
198 } elseif ( $field['tabs'] == 'text' ) {
199
200 // case: text tab only
201 $show_tabs = false;
202 } elseif ( wp_default_editor() == 'tinymce' ) {
203
204 // case: both tabs
205 $default_editor = 'tinymce';
206 }
207
208 // must be logged in to upload
209 if ( ! current_user_can( 'upload_files' ) ) {
210 $field['media_upload'] = 0;
211 }
212
213 // mode
214 $switch_class = ( $default_editor === 'html' ) ? 'html-active' : 'tmce-active';
215
216 // filter
217 add_filter( 'acf_the_editor_content', 'format_for_editor', 10, 2 );
218
219 $field['value'] = is_string( $field['value'] ) ? $field['value'] : '';
220 $field['value'] = apply_filters( 'acf_the_editor_content', $field['value'], $default_editor );
221
222 // attr
223 $wrap = array(
224 'id' => 'wp-' . $id . '-wrap',
225 'class' => 'acf-editor-wrap wp-core-ui wp-editor-wrap ' . $switch_class,
226 'data-toolbar' => $field['toolbar'],
227 );
228
229 // delay
230 if ( $field['delay'] ) {
231 $wrap['class'] .= ' delay';
232 }
233
234 // vars
235 $textarea = acf_get_textarea_input(
236 array(
237 'id' => $id,
238 'class' => 'wp-editor-area',
239 'name' => $field['name'],
240 'style' => $height ? "height:{$height}px;" : '',
241 'value' => '%s',
242 )
243 );
244
245 ?>
246 <div <?php echo acf_esc_attrs( $wrap ); ?>>
247 <div id="wp-<?php echo esc_attr( $id ); ?>-editor-tools" class="wp-editor-tools hide-if-no-js">
248 <?php if ( $field['media_upload'] ) : ?>
249 <div id="wp-<?php echo esc_attr( $id ); ?>-media-buttons" class="wp-media-buttons">
250 <?php
251 if ( ! function_exists( 'media_buttons' ) ) {
252 require ABSPATH . 'wp-admin/includes/media.php';
253 }
254 do_action( 'media_buttons', $id );
255 ?>
256 </div>
257 <?php endif; ?>
258 <?php if ( user_can_richedit() && $show_tabs ) : ?>
259 <div class="wp-editor-tabs">
260 <button id="<?php echo esc_attr( $id ); ?>-tmce" class="wp-switch-editor switch-tmce" data-wp-editor-id="<?php echo esc_attr( $id ); ?>" type="button"><?php esc_html_e( 'Visual', 'secure-custom-fields' ); ?></button>
261 <button id="<?php echo esc_attr( $id ); ?>-html" class="wp-switch-editor switch-html" data-wp-editor-id="<?php echo esc_attr( $id ); ?>" type="button"><?php echo esc_html_x( 'Text', 'Name for the Text editor tab (formerly HTML)', 'secure-custom-fields' ); ?></button>
262 </div>
263 <?php endif; ?>
264 </div>
265 <div id="wp-<?php echo esc_attr( $id ); ?>-editor-container" class="wp-editor-container">
266 <?php if ( $field['delay'] ) : ?>
267 <div class="acf-editor-toolbar"><?php esc_html_e( 'Click to initialize TinyMCE', 'secure-custom-fields' ); ?></div>
268 <?php endif; ?>
269 <?php printf( $textarea, $field['value'] ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- escaped by format_for_editor(). ?>
270 </div>
271 </div>
272 <?php
273 }
274
275
276 /**
277 * Create extra options for your field. This is rendered when editing a field.
278 * The value of $field['name'] can be used (like bellow) to save extra data to the $field
279 *
280 * @type action
281 * @since ACF 3.6
282 * @date 23/01/13
283 *
284 * @param $field - an array holding all the field's data
285 */
286 function render_field_settings( $field ) {
287 acf_render_field_setting(
288 $field,
289 array(
290 'label' => __( 'Default Value', 'secure-custom-fields' ),
291 'instructions' => __( 'Appears when creating a new post', 'secure-custom-fields' ),
292 'type' => 'textarea',
293 'name' => 'default_value',
294 )
295 );
296 }
297
298 /**
299 * Renders the field settings used in the "Presentation" tab.
300 *
301 * @since ACF 6.0
302 *
303 * @param array $field The field settings array.
304 * @return void
305 */
306 function render_field_presentation_settings( $field ) {
307 $toolbars = $this->get_toolbars();
308 $choices = array();
309
310 if ( ! empty( $toolbars ) ) {
311 foreach ( $toolbars as $k => $v ) {
312 $label = $k;
313 $name = sanitize_title( $label );
314 $name = str_replace( '-', '_', $name );
315
316 $choices[ $name ] = $label;
317 }
318 }
319
320 acf_render_field_setting(
321 $field,
322 array(
323 'label' => __( 'Tabs', 'secure-custom-fields' ),
324 'instructions' => '',
325 'type' => 'select',
326 'name' => 'tabs',
327 'choices' => array(
328 'all' => __( 'Visual & Text', 'secure-custom-fields' ),
329 'visual' => __( 'Visual Only', 'secure-custom-fields' ),
330 'text' => __( 'Text Only', 'secure-custom-fields' ),
331 ),
332 )
333 );
334
335 acf_render_field_setting(
336 $field,
337 array(
338 'label' => __( 'Toolbar', 'secure-custom-fields' ),
339 'instructions' => '',
340 'type' => 'select',
341 'name' => 'toolbar',
342 'choices' => $choices,
343 'conditions' => array(
344 'field' => 'tabs',
345 'operator' => '!=',
346 'value' => 'text',
347 ),
348 )
349 );
350
351 acf_render_field_setting(
352 $field,
353 array(
354 'label' => __( 'Show Media Upload Buttons', 'secure-custom-fields' ),
355 'instructions' => '',
356 'name' => 'media_upload',
357 'type' => 'true_false',
358 'ui' => 1,
359 )
360 );
361
362 acf_render_field_setting(
363 $field,
364 array(
365 'label' => __( 'Delay Initialization', 'secure-custom-fields' ),
366 'instructions' => __( 'TinyMCE will not be initialized until field is clicked', 'secure-custom-fields' ),
367 'name' => 'delay',
368 'type' => 'true_false',
369 'ui' => 1,
370 'conditions' => array(
371 'field' => 'tabs',
372 'operator' => '!=',
373 'value' => 'text',
374 ),
375 )
376 );
377 }
378 /**
379 * This filter is applied to the $value after it is loaded from the db, and before it is returned to the template
380 *
381 * @type filter
382 * @since ACF 3.6
383 *
384 * @param mixed $value The value which was loaded from the database.
385 * @param mixed $post_id The $post_id from which the value was loaded.
386 * @param array $field The field array holding all the field options.
387 * @param boolean $escape_html Should the field return a HTML safe formatted value.
388 * @return mixed $value The modified value
389 */
390 public function format_value( $value, $post_id, $field, $escape_html ) {
391 // Bail early if no value or not a string.
392 if ( empty( $value ) || ! is_string( $value ) ) {
393 return $value;
394 }
395
396 if ( $escape_html ) {
397 add_filter( 'acf_the_content', 'acf_esc_html', 1 );
398 }
399
400 $value = apply_filters( 'acf_the_content', $value );
401
402 if ( $escape_html ) {
403 remove_filter( 'acf_the_content', 'acf_esc_html', 1 );
404 }
405
406 // Follow the_content function in /wp-includes/post-template.php
407 return str_replace( ']]>', ']]&gt;', $value );
408 }
409 }
410
411
412 // initialize
413 acf_register_field_type( 'acf_field_wysiwyg' );
414 endif; // class_exists check
415
416 ?>
417