Answer the question
In order to leave comments, you need to log in
How to add TinyMCE text editor to plugin options page?
I am writing a plugin. There is a need to add TinyMCE to the plugin options page. I know what is done through wp_editor (), but how to add options to the "container" and assign text to a variable for subsequent saving and editing?
Answer the question
In order to leave comments, you need to log in
What do you mean by "add options to "container""?
Option 1, via php:
$set_of_buttons = add_filter('mce_buttons', create_function('', "return ['bold', 'italic', 'underline', 'bullist', 'numlist', 'alignleft', 'aligncenter', 'alignright', 'undo', 'redo'];")); // можно указать кнопки, которые будут в редакторе
$editor_params = [
'wpautop' => 0, // автоматически оборачивать абзацы в теги <p>
'media_buttons' => 0,
'textarea_name' => 'post_content', // параметр name для textarea, который будет в $_POST при передаче на сервер
'textarea_rows' => 10,
'tinymce' => $set_of_buttons,
'quicktags' => 0,
'drag_drop_upload' => 0
];
wp_editor( $content, $tiny_name, $editor_params ); // $content - сюда контент который сразу пихать в редактор; $tiny_name - имя для манипуляций через js; $editor_params - параметры
wp_enqueue_editor(); // подключает все скрипты и стили для tinyMCE
<textarea name="post-content" id="post-content" cols="30" rows="10"><?= $content ?></textarea>
tinymce.init({
selector:'#post-content',
branding: false,
toolbar1: 'bold italic underline | bullist numlist | alignleft aligncenter alignright | undo redo', // кнопки
content_css: ['//fonts.googleapis.com/css?family=Open+Sans:400,600&subset=cyrillic'], // подключаю шрифт покрасивше
menubar: false,
});
tinymce.triggerSave();
Container - option section on plugin settings page. The code below will be clearer, probably
Now I have a solution with textarea:
add_settings_section( 'now_open_section_widgetcontent', 'Содержание Виджетов', '', $now_open_page );
$now_open_field_params = array(
'type' => 'textarea',
'id' => 'now_open_opentxt',
'desc' => 'Например: "Мы Ждем Вас по адресу: Красная пл., 1. Добро пожаловать! "',
'label_for' => 'Виджет "Рабочее время"',
);
add_settings_field( 'txt', 'Ваше приветствие ', 'now_open_option_display_settings', $now_open_page, 'now_open_section_widgetcontent', $now_open_field_params );
switch ( $type ) {
case 'textarea':
$o[$id] = esc_attr( stripslashes($o[$id]) );
echo "<textarea class='code large-text' cols='50' rows='5' type='text' id='$id' name='" . $option_name . "[$id]'>$o[$id]</textarea>";
echo ($desc != '') ? "<br /><span class='description'>$desc</span>" : "";
break;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question