sanitize_title()
sanitize_title( string $title, string $fallback_title =…
sanitize_title( string $title, string $fallback_title = ”, string $context = ‘save’ )
清理标题,或返回回退标题。
Sanitizes a title, or returns a fallback title.
目录锚点:#说明#参数#源码#笔记
说明(Description)
具体来说,HTML和PHP标记被剥离。可以通过插件API添加进一步的操作。如果$title为空并且设置了$fallback_title,则将使用后者。
参数(Parameters)
| 参数 | 类型 | 说明 |
|---|---|---|
| $title | (string) | 要清理的字符串。 |
| $fallback_title | (string) | $title为空时使用的标题。 |
| $context | (string) | 对其字符串进行清理的操作 |
源码(Source)
/**
* Sanitizes a title, or returns a fallback title.
*
* Specifically, HTML and PHP tags are stripped. Further actions can be added
* via the plugin API. If $title is empty and $fallback_title is set, the latter
* will be used.
*
* @since 1.0.0
*
* @param string $title The string to be sanitized.
* @param string $fallback_title Optional. A title to use if $title is empty.
* @param string $context Optional. The operation for which the string is sanitized
* @return string The sanitized string.
*/
function sanitize_title( $title, $fallback_title = '', $context = 'save' ) {
$raw_title = $title;
if ( 'save' == $context )
$title = remove_accents($title);
/**
* Filter a sanitized title string.
*
* @since 1.2.0
*
* @param string $title Sanitized title.
* @param string $raw_title The title prior to sanitization.
* @param string $context The context for which the title is being sanitized.
*/
$title = apply_filters( 'sanitize_title', $title, $raw_title, $context );
if ( '' === $title || false === $title )
$title = $fallback_title;
return $title;
}| 更新版本 | 源码位置 | 使用 | 被使用 |
|---|---|---|---|
| 1.0.0 | wp-includes/formatting.php | 5 | 10 |
笔记(Notes)
WordPress标题
类别:WordPress 函数手册、
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。
还没有任何评论,赶紧来占个楼吧!