对数据库或重定向使用执行esc_url()。
原型
sanitize_url( string $url, array $protocols = null )
参数
$url
(string)
(Required)
要清理的URL。
$protocols
(array)
(Optional)
一系列可接受的协议。
返回值
(string)
已清理的网址。
源文件
路径:wp-includes/deprecated.php
<?php
...
function sanitize_url( $url, $protocols = null ) {
_deprecated_function( __FUNCTION__, '2.8.0', 'esc_url_raw()' );
return esc_url_raw( $url, $protocols );
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/sanitize_url/