On this page
format_for_editor( string $text, string $default_editor = null ): string
Formats text for the editor.
Description
Generally the browsers treat everything inside a textarea as text, but it is still a good idea to HTML entity encode <, > and & in the content.
The filter ‘format_for_editor’ is applied here. If $text is empty the filter will be applied to an empty string.
See also
Parameters
$textstring Required-
The text to be formatted.
$default_editorstring Optional-
The default editor for the current user.
It is usually either'html'or'tinymce'.Default:
null
Return
string The formatted text after filter is applied.
Source
File: wp-includes/formatting.php. View all references
function format_for_editor( $text, $default_editor = null ) {
if ( $text ) {
$text = htmlspecialchars( $text, ENT_NOQUOTES, get_option( 'blog_charset' ) );
}
/**
* Filters the text after it is formatted for the editor.
*
* @since 4.3.0
*
* @param string $text The formatted text.
* @param string $default_editor The default editor for the current user.
* It is usually either 'html' or 'tinymce'.
*/
return apply_filters( 'format_for_editor', $text, $default_editor );
}
Hooks
- apply_filters( 'format_for_editor',
string $text ,string $default_editor ) -
Filters the text after it is formatted for the editor.
Related
Uses
| Uses | Description |
|---|---|
| apply_filters() wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. |
| get_option() wp-includes/option.php | Retrieves an option value based on an option name. |
Changelog
| Version | Description |
|---|---|
| 4.3.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/format_for_editor