sanitize_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标题
sanitize_title() 为WP2原创文章,链接:https://www.wp2.cn/functions/sanitize_title/