format_to_edit() WordPress Function

The format_to_edit() function is used to format a string for editing in a text area. This function is especially useful for ensuring that line breaks are retained in a string when it is edited in a text area.

format_to_edit( string $content, bool $rich_text = false ) #

Acts on text which is about to be edited.


Description

The $content is run through esc_textarea(), which uses htmlspecialchars() to convert special characters to HTML entities. If $richedit is set to true, it is simply a holder for the ‘format_to_edit’ filter.


Top ↑

Parameters

$content

(string)(Required)The text about to be edited.

$rich_text

(bool)(Optional) Whether $content should be considered rich text, in which case it would not be passed through esc_textarea().

Default value: false


Top ↑

Return

(string) The text after the filter (and possibly htmlspecialchars()) has been run.


Top ↑

Source

File: wp-includes/formatting.php

function format_to_edit( $content, $rich_text = false ) {
	/**
	 * Filters the text to be formatted for editing.
	 *
	 * @since 1.2.0
	 *
	 * @param string $content The text, prior to formatting for editing.
	 */
	$content = apply_filters( 'format_to_edit', $content );
	if ( ! $rich_text ) {
		$content = esc_textarea( $content );
	}
	return $content;
}


Top ↑

Changelog

Changelog
VersionDescription
4.4.0The $richedit parameter was renamed to $rich_text for clarity.
0.71Introduced.

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