format_for_editor

函式
format_for_editor ( $text, $default_editor = null )
引數
  • (string) $text The text to be formatted.
    Required:
  • (string) $default_editor The default editor for the current user. It is usually either 'html' or 'tinymce'.
    Required:
    Default: null
返回值
  • (string) The formatted text after filter is applied.
相關
  • _WP_Editors::editor()
定義位置
相關方法
format_to_editedit_form_image_editormedia_send_to_editorthe_editorimage_constrain_size_for_editor
引入
4.3.0
棄用
-

format_for_editor: 這個函式用來格式化文字以在WordPress編輯器中顯示。它把某些字元和實體轉換為它們相應的HTML實體。

為編輯器形成文字。

一般來說,瀏覽器會將文字框內的所有內容視為文字,但在內容中對HTML實體編碼“和`&`仍然是一個好主意。

過濾器{@see ‘format_for_editor’}在這裡被應用。如果`$text`是空的,過濾器將被應用於一個空字串。

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

常見問題

FAQs
檢視更多 >