函数文档

clean_pre()

💡 云策文档标注

概述

clean_pre() 是一个已弃用的 WordPress 函数,用于在 wpautop() 中处理 preg_replace_callback 的匹配数组或字符串,确保 HTML pre 块内容不被转换为段落或换行。

关键要点

  • 函数接受 preg_replace_callback 的匹配数组或字符串作为参数
  • 主要功能是防止 pre 块内容被自动转换为段落或换行符
  • 在 WordPress 3.4.0 版本中已弃用,最初在 1.2.0 版本引入
  • 返回处理后的字符串,移除特定换行和空格转换

代码示例

function clean_pre($matches) {
    _deprecated_function( __FUNCTION__, '3.4.0' );

    if ( is_array($matches) )
        $text = $matches[1] . $matches[2] . "";
    else
        $text = $matches;

    $text = str_replace(array('', '', ''), array('', '', ''), $text);
    $text = str_replace('', "n", $text);
    $text = str_replace('', '', $text);

    return $text;
}

注意事项

  • 此函数已弃用,不建议在新代码中使用,应寻找替代方案
  • 相关函数 _deprecated_function() 用于标记弃用并通知使用情况

📄 原文内容

Accepts matches array from preg_replace_callback in wpautop() or a string.

Description

Ensures that the contents of a <pre>...</pre> HTML block are not converted into paragraphs or line breaks.

Parameters

$matchesarray|stringrequired
The array or string

Return

string The pre block without paragraph/line break conversion.

Source

function clean_pre($matches) {
	_deprecated_function( __FUNCTION__, '3.4.0' );

	if ( is_array($matches) )
		$text = $matches[1] . $matches[2] . "</pre>";
	else
		$text = $matches;

	$text = str_replace(array('<br />', '<br/>', '<br>'), array('', '', ''), $text);
	$text = str_replace('<p>', "n", $text);
	$text = str_replace('</p>', '', $text);

	return $text;
}

Changelog

Version Description
3.4.0 Deprecated.
1.2.0 Introduced.