wp_parse_slug_list()
云策文档标注
概述
wp_parse_slug_list() 函数用于清理一个数组、逗号或空格分隔的 slug 列表,返回去重后的 sanitized slug 数组。
关键要点
- 参数 $input_list 可以是数组或字符串,必需,表示 slug 列表。
- 返回值是字符串数组,即经过 sanitize_title() 处理并去重后的 slug 数组。
- 内部调用 wp_parse_list() 将输入转换为数组,然后使用 array_map() 和 sanitize_title() 清理每个 slug,最后用 array_unique() 去重。
- 相关函数包括 wp_parse_list(),用于将逗号或空格分隔的标量值列表转换为数组。
- 在 WordPress 5.1.0 中重构以使用 wp_parse_list(),最初在 4.7.0 版本引入。
代码示例
function wp_parse_slug_list( $input_list ) {
$input_list = wp_parse_list( $input_list );
return array_unique( array_map( 'sanitize_title', $input_list ) );
}
原文内容
Cleans up an array, comma- or space-separated list of slugs.
Parameters
$input_listarray|stringrequired-
List of slugs.
Source
function wp_parse_slug_list( $input_list ) {
$input_list = wp_parse_list( $input_list );
return array_unique( array_map( 'sanitize_title', $input_list ) );
}
Changelog
| Version | Description |
|---|---|
| 5.1.0 | Refactored to use wp_parse_list() . |
| 4.7.0 | Introduced. |