腾讯云服务器优惠活动华纳云香港服务器

WordPress函数wp_allowed_protocols,检索要在HTML属性中允许的协议列表

WordPress主题推荐

WordPress在 检查和清理URL地址时需要用到一个参数就是$protocols,即是一些列可接受的协议,默认返回wp_allowed_protocols()。

wp_allowed_protocols(): string[]

返回允许的协议数组,允许的协议包括http、https、ftp、ftps、mailto、news、irc、irc6、ircs、gopher、nntp、feed、telnet、mms、rtsp、sms、svn、tel、fax、xmpp、webcal、urn、javascript。

如果不在协议列表中,就会返回空字符串,所以如果你想要添加一些额外的协议到允许的协议列表中,可以使用以下代码实现:

apply_filters( 'kses_allowed_protocols', string[] $protocols )

比如:

/**
* Extend list of allowed protocols.
*
* @param array $protocols List of default protocols allowed by WordPress.
*
* @return array $protocols Updated list including new protocols.
*/
function wporg_extend_allowed_protocols( $protocols ){
$protocols[] = 'skype';
$protocols[] = 'spotify';
$protocols[] = 'macappstores';
return $protocols;
}
add_filter( 'kses_allowed_protocols' , 'wporg_extend_allowed_protocols' );

本文地址:https://boke112.com/post/8011.html

赞 (4) 打赏
版权声明:本文内容来源于互联网资源,由 boke112百科 整理汇总!发布此文是出于传递更多信息之目的,若有来源标注错误或侵犯了您的合法权益,请联系我们,确认后马上更正或删除,谢谢!
wu