format_for_editor

Formats text for the editor.

Description

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

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 is applied here. If $text is empty the filter will be applied to an empty string.

Returns (string)

The formatted text after filter is applied.

Parameters (2)

0. $text (string)
The text to be formatted.
1. $default_editor — Optional. (null) => null
The default editor for the current user. It is usually either html or tinymce..

Usage

  1. if ( !function_exists( 'format_for_editor' ) ) { 
  2. require_once ABSPATH . WPINC . '/formatting.php'; 
  3.  
  4. // The text to be formatted. 
  5. $text = ''; 
  6.  
  7. // The default editor for the current user. 
  8. // It is usually either 'html' or 'tinymce'. 
  9. $default_editor = null; 
  10.  
  11. // NOTICE! Understand what this does before running. 
  12. $result = format_for_editor($text, $default_editor); 
  13.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/formatting.php  
  1. function format_for_editor( $text, $default_editor = null ) { 
  2. if ( $text ) { 
  3. $text = htmlspecialchars( $text, ENT_NOQUOTES, get_option( 'blog_charset' ) ); 
  4.  
  5. /** 
  6. * Filters the text after it is formatted for the editor. 
  7. * @since 4.3.0 
  8. * @param string $text The formatted text. 
  9. * @param string $default_editor The default editor for the current user. 
  10. * It is usually either 'html' or 'tinymce'. 
  11. */ 
  12. return apply_filters( 'format_for_editor', $text, $default_editor );