积木别倒

  • 首页
  • 科学上网
  • 机场推荐
  • 网站搭建
  • 网站分享
  • 其他
记录、分享
小白折腾之路
  1. 首页
  2. 其他
  3. 正文

Wordpress 超链接增加 magnet、ed2k、tg 新协议支持

11月 12, 2020 1974点热度 0人点赞 0条评论

需要在Wordpress的超链接中增加对magnet、ed2k等新协议的支持,效果类似:

肖申克的救赎

为防范SQL注入、XSS等攻击,Wordpress会在保存博客内容时候,对内容自动过滤,导致会对超链接中不支持的协议protocol头(例如:magnet:?xt=urn:btih: ),自动删除掉。

google结果,大部分都是简单粗暴的方案:

修改 wp-includes/post.php,将相关内容注释掉。

//$postarr = sanitize_post($postarr, 'db');

但这样放弃了Wordpress原本的防范措施,不建议采用。

如果想让网页实现跳转到telegram,使用tg开头的链接,虽然使用此方法可行但也不推荐。

推荐的解决办法:

方案1:修改 wp-includes/functions.php,增加新协议支持

修改 wp-includes/functions.php 的function wp_allowed_protocols()

if ( empty( $protocols ) ) {
 $protocols = array( 'http', 'https', 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 
'telnet', 'mms', 'rtsp', 'sms', 'svn', 'tel', 'fax', 'xmpp', 'webcal', 'urn' );
        }

直接增加需要添加的新协议,例如:

        if ( empty( $protocols ) ) {
$protocols = array( 'http', 'https', 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 
'telnet', 'mms', 'rtsp', 'sms', 'svn', 'tel', 'fax', 'xmpp', 'webcal', 'urn' ,'magnet','ed2k','tg');
        }

此种方案存在一个问题:由于是全局性修改,Wordpress每一次版本升级,都会覆盖修改functions.php 文件,必须手工再次修改此文件。

如果想让Wordpress 支持 tg:// 实现跳转到 Telegram,使用tg开头的链接,则使用此方法可行。

vi /var/www/html/wp-includes/functions.php

方案2:在现有主题theme,增加新协议支持

修改 wp-content/themes/对应的theme名称/functions.php ,增加如下内容:

function ss_allow_magnet_protocol( $protocols ){
    $protocols[] = 'magnet';
    return $protocols;
}
function ss_allow_ed2k_protocol( $protocols ){
    $protocols[] = 'ed2k';
    return $protocols;
}
add_filter( 'kses_allowed_protocols' , 'ss_allow_magnet_protocol' );
add_filter( 'kses_allowed_protocols' , 'ss_allow_ed2k_protocol' );
function ss_allow_tg_protocol( $protocols ){
$protocols[] = 'tg';
return $protocols;
}
add_filter( 'kses_allowed_protocols' , 'ss_allow_tg_protocol' );

设置清除网页缓存,刷新即发现链接格式已经生效。

原文地址:https://www.yeeach.com/post/1565

本作品采用 知识共享署名 4.0 国际许可协议 进行许可
标签: wordpress
最后更新:5月 13, 2021

积木

这个人很懒,什么都没留下

点赞
< 上一篇
下一篇 >

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

Telegram
📢 频道:积木别倒
🏄 群组:翻墙交流群
最新 热点 随机
最新 热点 随机
盘点个人喜欢的女优们 [转载]监控你的机场链路质量(Windows) 听说速蛙云机场跑路了,怎么才选到稳定靠谱的机场呢? Macbook 安装 homebrew 教程 Backlinko 的谷歌 SEO 建议 2023 年 9 个订阅链接转换网站推荐
盘点个人喜欢的女优们
Telegram iOS 端经常无故卡死解决办法 VPS 手动安装最新 MTProxy( mtg 2.0 )代理教程 centos7手动搭建shadowsocks服务,支持aes-256-gcm VPS一键脚本快速搭建trojan 代理服务 Surge 配置 Trojan 协议教程 MTProxy Python 版一键安装教程,支持多用户管理
归档
  • 2023年3月
  • 2022年8月
  • 2022年7月
  • 2021年12月
  • 2021年11月
  • 2021年10月
  • 2021年7月
  • 2021年6月
  • 2021年5月
  • 2021年4月
  • 2021年3月
  • 2021年1月
  • 2020年11月
  • 2020年10月
  • 2020年8月
  • 2020年7月
  • 2020年6月
  • 2020年5月
  • 2020年4月
  • 2020年3月
  • 2019年9月
  • 2019年8月
  • 2019年4月
  • 2019年3月
标签聚合
Docker 美区Apple ID wordpress 在线书签 Google Voice 翻墙机场 mtproxy Trojan shadowsocks 机场稳定性监测 黄色废料 一键脚本 telegram 订阅转换 mtg FFmpeg

COPYRIGHT © 2023 jimubiedao.com. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang