the_editor_content
Устанавливает предварительный контент/текст для редактора WordPress. Т.е. текст по умолчанию.
C помощью этого фильтра можно, например, установить начальный контент для типа записи, при создании новой записи.
Есть еще аналогичный хук 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 for the current user. Either 'html' or '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 289
$content = apply_filters( 'the_editor_content', $content, $default_editor );
wp-includes/widgets/class-wp-widget-text.php 474
$text = apply_filters( 'the_editor_content', $instance['text'], $default_editor );
Где используется хук в WordPress
wp-includes/class-wp-editor.php 277
add_filter( 'the_editor_content', 'format_for_editor', 10, 2 );
wp-includes/class-wp-editor.php 293
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 );
wp-includes/widgets/class-wp-widget-text.php 478
remove_filter( 'the_editor_content', 'format_for_editor' );