File "class-acf-field-wysiwyg.php"
Full path: /home/kosmetik/public_html/wp-content/plugins/advanced-custom-fields/includes/fields/class-acf-field-wysiwyg.php
File
size: 9.14 B
MIME-type: text/x-php
Charset: utf-8
Download Open Edit Advanced Editor Back
<?php
if (!class_exists('acf_field_wysiwyg')) {
class acf_field_wysiwyg extends acf_field
{
function initialize()
{
$this->name = 'wysiwyg';
$this->label = __('Wysiwyg Editor', 'acf');
$this->category = 'content';
$this->defaults = array('tabs' => 'all', 'toolbar' => 'full', 'media_upload' => 1, 'default_value' => '', 'delay' => 0);
$this->add_filters();
add_action('acf/enqueue_uploader', array($this, 'acf_enqueue_uploader'));
}
function add_filters()
{
$wp_filter_content_tags = function_exists('wp_filter_content_tags') ? 'wp_filter_content_tags' : 'wp_make_content_images_responsive';
add_filter('acf_the_content', 'capital_P_dangit', 11);
add_filter('acf_the_content', 'wptexturize');
add_filter('acf_the_content', 'convert_smilies', 20);
add_filter('acf_the_content', 'wpautop');
add_filter('acf_the_content', 'shortcode_unautop');
add_filter('acf_the_content', $wp_filter_content_tags);
add_filter('acf_the_content', 'do_shortcode', 11);
if (isset($GLOBALS['wp_embed'])) {
add_filter('acf_the_content', array($GLOBALS['wp_embed'], 'run_shortcode'), 8);
add_filter('acf_the_content', array($GLOBALS['wp_embed'], 'autoembed'), 8);
}
}
function get_toolbars()
{
$editor_id = 'acf_content';
$toolbars = array();
$mce_buttons = array('formatselect', 'bold', 'italic', 'bullist', 'numlist', 'blockquote', 'alignleft', 'aligncenter', 'alignright', 'link', 'wp_more', 'spellchecker', 'fullscreen', 'wp_adv');
$mce_buttons_2 = array('strikethrough', 'hr', 'forecolor', 'pastetext', 'removeformat', 'charmap', 'outdent', 'indent', 'undo', 'redo', 'wp_help');
$teeny_mce_buttons = array('bold', 'italic', 'underline', 'blockquote', 'strikethrough', 'bullist', 'numlist', 'alignleft', 'aligncenter', 'alignright', 'undo', 'redo', 'link', 'fullscreen');
if (acf_version_compare('wp', '<', '4.7')) {
$mce_buttons = array('bold', 'italic', 'strikethrough', 'bullist', 'numlist', 'blockquote', 'hr', 'alignleft', 'aligncenter', 'alignright', 'link', 'unlink', 'wp_more', 'spellchecker', 'fullscreen', 'wp_adv');
$mce_buttons_2 = array('formatselect', 'underline', 'alignjustify', 'forecolor', 'pastetext', 'removeformat', 'charmap', 'outdent', 'indent', 'undo', 'redo', 'wp_help');
}
$toolbars['Full'] = array(1 => apply_filters('mce_buttons', $mce_buttons, $editor_id), 2 => apply_filters('mce_buttons_2', $mce_buttons_2, $editor_id), 3 => apply_filters('mce_buttons_3', array(), $editor_id), 4 => apply_filters('mce_buttons_4', array(), $editor_id));
$toolbars['Basic'] = array(1 => apply_filters('teeny_mce_buttons', $teeny_mce_buttons, $editor_id));
$toolbars = apply_filters('acf/fields/wysiwyg/toolbars', $toolbars);
return $toolbars;
}
function acf_enqueue_uploader()
{
$data = array();
$toolbars = $this->get_toolbars();
if ($toolbars) {
foreach ($toolbars as $label => $rows) {
$key = $label;
$key = sanitize_title($key);
$key = str_replace('-', '_', $key);
$data[$key] = array();
if ($rows) {
foreach ($rows as $i => $row) {
$data[$key][$i] = implode(',', $row);
}
}
}
}
acf_localize_data(array('toolbars' => $data));
}
function render_field($field)
{
acf_enqueue_uploader();
$id = uniqid('acf-editor-');
$default_editor = 'html';
$show_tabs = true;
$height = acf_get_user_setting('wysiwyg_height', 300);
$height = max($height, 300);
if (!user_can_richedit()) {
$show_tabs = false;
} elseif ($field['tabs'] == 'visual') {
$default_editor = 'tinymce';
$show_tabs = false;
} elseif ($field['tabs'] == 'text') {
$show_tabs = false;
} elseif (wp_default_editor() == 'tinymce') {
$default_editor = 'tinymce';
}
if (!current_user_can('upload_files')) {
$field['media_upload'] = 0;
}
$switch_class = $default_editor === 'html' ? 'html-active' : 'tmce-active';
add_filter('acf_the_editor_content', 'format_for_editor', 10, 2);
$field['value'] = apply_filters('acf_the_editor_content', $field['value'], $default_editor);
$wrap = array('id' => 'wp-' . $id . '-wrap', 'class' => 'acf-editor-wrap wp-core-ui wp-editor-wrap ' . $switch_class, 'data-toolbar' => $field['toolbar']);
if ($field['delay']) {
$wrap['class'] .= ' delay';
}
$textarea = acf_get_textarea_input(array('id' => $id, 'class' => 'wp-editor-area', 'name' => $field['name'], 'style' => $height ? "height:{$height}px;" : '', 'value' => '%s'));
?>
<div <?php
acf_esc_attr_e($wrap);
?>>
<div id="wp-<?php
echo esc_attr($id);
?>-editor-tools" class="wp-editor-tools hide-if-no-js">
<?php
if ($field['media_upload']) {
?>
<div id="wp-<?php
echo esc_attr($id);
?>-media-buttons" class="wp-media-buttons">
<?php
if (!function_exists('media_buttons')) {
require ABSPATH . 'wp-admin/includes/media.php';
}
do_action('media_buttons', $id);
?>
</div>
<?php
}
?>
<?php
if (user_can_richedit() && $show_tabs) {
?>
<div class="wp-editor-tabs">
<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
echo __('Visual', 'acf');
?></button>
<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 _x('Text', 'Name for the Text editor tab (formerly HTML)', 'acf');
?></button>
</div>
<?php
}
?>
</div>
<div id="wp-<?php
echo esc_attr($id);
?>-editor-container" class="wp-editor-container">
<?php
if ($field['delay']) {
?>
<div class="acf-editor-toolbar"><?php
_e('Click to initialize TinyMCE', 'acf');
?></div>
<?php
}
?>
<?php
printf($textarea, $field['value']);
?>
</div>
</div>
<?php
}
function render_field_settings($field)
{
$toolbars = $this->get_toolbars();
$choices = array();
if (!empty($toolbars)) {
foreach ($toolbars as $k => $v) {
$label = $k;
$name = sanitize_title($label);
$name = str_replace('-', '_', $name);
$choices[$name] = $label;
}
}
acf_render_field_setting($field, array('label' => __('Default Value', 'acf'), 'instructions' => __('Appears when creating a new post', 'acf'), 'type' => 'textarea', 'name' => 'default_value'));
acf_render_field_setting($field, array('label' => __('Tabs', 'acf'), 'instructions' => '', 'type' => 'select', 'name' => 'tabs', 'choices' => array('all' => __('Visual & Text', 'acf'), 'visual' => __('Visual Only', 'acf'), 'text' => __('Text Only', 'acf'))));
acf_render_field_setting($field, array('label' => __('Toolbar', 'acf'), 'instructions' => '', 'type' => 'select', 'name' => 'toolbar', 'choices' => $choices, 'conditions' => array('field' => 'tabs', 'operator' => '!=', 'value' => 'text')));
acf_render_field_setting($field, array('label' => __('Show Media Upload Buttons?', 'acf'), 'instructions' => '', 'name' => 'media_upload', 'type' => 'true_false', 'ui' => 1));
acf_render_field_setting($field, array('label' => __('Delay initialization?', 'acf'), 'instructions' => __('TinyMCE will not be initialized until field is clicked', 'acf'), 'name' => 'delay', 'type' => 'true_false', 'ui' => 1, 'conditions' => array('field' => 'tabs', 'operator' => '!=', 'value' => 'text')));
}
function format_value($value, $post_id, $field)
{
if (empty($value)) {
return $value;
}
$value = apply_filters('acf_the_content', $value);
$value = str_replace(']]>', ']]>', $value);
return $value;
}
}
acf_register_field_type('acf_field_wysiwyg');
}