the_editor
Изменяет HTML разметку редактора WordPress (html к которому затем подключается tyniMCE и quicktag).
Этот хук может пригодится, когда в html редактора нужно добавить нестандартный атрибут тега или добавить какой-то элемент. Это можно сделать с помощью str_replace().
Использование
add_filter( 'the_editor', 'wp_kama_the_editor_filter' );
/**
* Function for `the_editor` filter-hook.
*
* @param string $output Editor's HTML markup.
*
* @return string
*/
function wp_kama_the_editor_filter( $output ){
// filter...
return $output;
}
- $output(строка)
HTML код визуального редактора.
По умолчанию параметр содержит такой HTML:
'<div id="wp-' . $editor_id_attr . '-editor-container" class="wp-editor-container">' . $quicktags_toolbar . '<textarea' . $editor_class . $height . $tabindex . $autocomplete . ' cols="40" name="' . esc_attr( $set['textarea_name'] ) . '" ' . 'id="' . $editor_id_attr . '">%s</textarea></div>'
Примеры
#1 Заменяем часть формы редактирования поста
add_filter('the_editor', 'the_editor_demo_funct');
function the_editor_demo_funct( $wrapper ) {
if ( false !== strpos($wrapper, 'id="content"') ) {
$wrapper = str_replace('</textarea>', '</textarea><p>Вписывайте текст в это поле.</p>', $wrapper );
}
return $wrapper;
}
Список изменений
| С версии 2.1.0 | Введена. |
Где вызывается хук
wp-includes/class-wp-editor.php 267-273
$the_editor = apply_filters( 'the_editor', '<div id="wp-' . $editor_id_attr . '-editor-container" class="wp-editor-container">' . $quicktags_toolbar . '<textarea' . $editor_class . $height . $tabindex . $autocomplete . ' cols="40" name="' . esc_attr( $set['textarea_name'] ) . '" ' . 'id="' . $editor_id_attr . '">%s</textarea></div>' );