函数文档

wp_htmledit_pre()

💡 云策文档标注

概述

wp_htmledit_pre() 是一个已弃用的 WordPress 函数,用于为 HTML 编辑器格式化文本。它通过 htmlspecialchars 处理输出,并应用 'htmledit_pre' 过滤器,但自 4.3.0 版本起被 format_for_editor() 替代。

关键要点

  • 函数 wp_htmledit_pre() 已弃用,建议使用 format_for_editor()。
  • 除非 $output 为空,否则会先通过 htmlspecialchars 转换特殊字符(如 ' 和 &),再应用 'htmledit_pre' 过滤器。
  • 返回格式化后的文本字符串。

代码示例

function wp_htmledit_pre($output) {
    _deprecated_function( __FUNCTION__, '4.3.0', 'format_for_editor()' );

    if ( !empty($output) )
        $output = htmlspecialchars($output, ENT_NOQUOTES, get_option( 'blog_charset' ) ); // Convert only ' &'.

    /**
     * Filters the text before it is formatted for the HTML editor.
     *
     * @since 2.5.0
     * @deprecated 4.3.0
     *
     * @param string $output The HTML-formatted text.
     */
    return apply_filters( 'htmledit_pre', $output );
}

注意事项

  • 此函数自 WordPress 4.3.0 起弃用,开发者应迁移到 format_for_editor() 以避免兼容性问题。
  • 使用 htmlspecialchars 时,参数 ENT_NOQUOTES 确保只转换单引号和 & 符号,不转换双引号。
  • 相关函数包括 _deprecated_function()、apply_filters() 和 get_option()。

📄 原文内容

Formats text for the HTML editor.

Description

Unless $output is empty it will pass through htmlspecialchars before the ‘htmledit_pre’ filter is applied.

See also

Parameters

$outputstringrequired
The text to be formatted.

Return

string Formatted text after filter applied.

Source

function wp_htmledit_pre($output) {
	_deprecated_function( __FUNCTION__, '4.3.0', 'format_for_editor()' );

	if ( !empty($output) )
		$output = htmlspecialchars($output, ENT_NOQUOTES, get_option( 'blog_charset' ) ); // Convert only '< > &'.

	/**
	 * Filters the text before it is formatted for the HTML editor.
	 *
	 * @since 2.5.0
	 * @deprecated 4.3.0
	 *
	 * @param string $output The HTML-formatted text.
	 */
	return apply_filters( 'htmledit_pre', $output );
}

Hooks

apply_filters( ‘htmledit_pre’, string $output )

Filters the text before it is formatted for the HTML editor.

Changelog

Version Description
4.3.0 Deprecated. Use format_for_editor()
2.5.0 Introduced.