函数文档

wp_richedit_pre()

💡 云策文档标注

概述

wp_richedit_pre() 是一个已弃用的 WordPress 函数,用于为富文本编辑器格式化文本。它应用 'richedit_pre' 过滤器,并自 4.3.0 版本起被 format_for_editor() 替代。

关键要点

  • 函数 wp_richedit_pre() 已弃用,建议使用 format_for_editor() 替代。
  • 如果输入文本为空,函数会应用 'richedit_pre' 过滤器到空字符串;否则,先通过 convert_chars()、wpautop() 和 htmlspecialchars() 处理文本,再应用过滤器。
  • 相关 Hook 包括 apply_filters('richedit_pre', $output),用于过滤返回给富文本编辑器的文本。

代码示例

function wp_richedit_pre($text) {
    _deprecated_function( __FUNCTION__, '4.3.0', 'format_for_editor()' );

    if ( empty( $text ) ) {
        return apply_filters( 'richedit_pre', '' );
    }

    $output = convert_chars($text);
    $output = wpautop($output);
    $output = htmlspecialchars($output, ENT_NOQUOTES, get_option( 'blog_charset' ) );

    return apply_filters( 'richedit_pre', $output );
}

注意事项

  • 此函数自 WordPress 4.3.0 起弃用,开发者应迁移到 format_for_editor() 以避免兼容性问题。
  • 函数内部处理包括字符转换、段落自动添加和 HTML 特殊字符转义,确保文本在富文本编辑器中的正确显示。

📄 原文内容

Formats text for the rich text editor.

Description

The ‘richedit_pre’ filter is applied here. If $text is empty the filter will be applied to an empty string.

See also

Parameters

$textstringrequired
The text to be formatted.

Return

string The formatted text after filter is applied.

Source

function wp_richedit_pre($text) {
	_deprecated_function( __FUNCTION__, '4.3.0', 'format_for_editor()' );

	if ( empty( $text ) ) {
		/**
		 * Filters text returned for the rich text editor.
		 *
		 * This filter is first evaluated, and the value returned, if an empty string
		 * is passed to wp_richedit_pre(). If an empty string is passed, it results
		 * in a break tag and line feed.
		 *
		 * If a non-empty string is passed, the filter is evaluated on the wp_richedit_pre()
		 * return after being formatted.
		 *
		 * @since 2.0.0
		 * @deprecated 4.3.0
		 *
		 * @param string $output Text for the rich text editor.
		 */
		return apply_filters( 'richedit_pre', '' );
	}

	$output = convert_chars($text);
	$output = wpautop($output);
	$output = htmlspecialchars($output, ENT_NOQUOTES, get_option( 'blog_charset' ) );

	/** This filter is documented in wp-includes/deprecated.php */
	return apply_filters( 'richedit_pre', $output );
}

Hooks

apply_filters( ‘richedit_pre’, string $output )

Filters text returned for the rich text editor.

Changelog

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