the_editor_content
Встановлює попередній текст/текст для редактора WordPress. Тобто. текст за промовчанням.
За допомогою цього фільтра можна, наприклад, встановити початковий контент типу запису, при створенні нового запису.
Є ще аналогічний хук default_content, який встановлює контент за промовчанням для запису, а не для редактора. Він спрацьовує за будь-якої публікації запису: навіть при press-this, xmlrpc і т.д. Обидва хуки взаємозамінні у 80% випадків.
Також, є подібні хуки:
- для заголовка –
default_title - для цитати:
default_excerpt.
Використання
add_filter( 'the_editor_content', 'wp_kama_the_editor_content_filter', 10, 2);
/**
* Function for `the_editor_content` filter-hook.
*
* @param string $content Default editor content.
* @param string $default_editor The default editor для поточного користувача. Either 'html' або 'tinymce'.
*
* @return string
*/
function wp_kama_the_editor_content_filter( $content, $default_editor ){
// Filter...
return $content;
}- $content
(рядок) - Контент, який буде встановлений у редактор WordPress.
Приклади
#1 Встановимо початковий контент для типу записуxxx
add_filter('the_editor_content', 'new_xxx_content');
function new_xxx_content( $content ){
global $post;
// Встановлюємо текст тільки якщо контенту ще немає і це потрібний тип запису
if( empty( $content ) && $post->post_type == 'xxx' ){
return 'Це початковий текст для запису.';
}
return $content;
}
#2 Встановимо стандартний контент через хук ‘default_content’
add_filter( 'default_content', 'custom_post_type_content' );
function custom_post_type_content( $content ) {
if( function_exists('get_current_screen') && get_current_screen()->post_type == 'my_post') {
$content = 'Контент за промовчанням для постів типу: "my_post"';
return $content;
}
}
список змін
| З версії 2.1.0 | Введено. |
Де викликається хук
the_editor_content
wp-includes/class-wp-editor.php 284
$content = apply_filters( 'the_editor_content', $content, $default_editor );
Де використовується хук у WordPress
wp-includes/class-wp-editor.php 288
remove_filter( 'the_editor_content', 'format_for_editor');
wp-includes/widgets/class-wp-widget-text.php 467
add_filter( 'the_editor_content', 'format_for_editor', 10, 2);