format_for_editor() WordPress Function

The format_for_editor() function formats text for the WordPress editor. This function can be used to convert plain text to HTML, or to convert HTML to plain text. This function can be useful for converting text from a word processor or other text editor to HTML, or for converting HTML to a format that can be edited in a word processor or other text editor.

format_for_editor( string $text, string $default_editor = null ) #

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.

Top ↑

See also


Top ↑

Parameters

$text

(string)(Required)The text to be formatted.

$default_editor

(string)(Optional)The default editor for the current user. It is usually either 'html' or 'tinymce'.

Default value: null


Top ↑

Return

(string) The formatted text after filter is applied.


Top ↑

Source

File: wp-includes/formatting.php

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 );
}


Top ↑

Changelog

Changelog
VersionDescription
4.3.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More