WP接入七牛图片样式及防盗链配置

WordPress 云上的幻象 11个月前 (05-13) 433次浏览 7个评论 扫描二维码

昨天接入了七牛云存储,面临一些设置,就是图片样式接口的调用及防盗链的设置,下面我们依次说下两者的解决方法。

防盗链配置

先来说说防盗链该如何配置,就来说说Referer 防盗链吧,因为时间戳防盗链搞了半天没搞好,以后找到解决方法在分享出来。下面咱们看图:

WP接入七牛图片样式及防盗链配置 WP接入七牛图片样式及防盗链配置 WP接入七牛图片样式及防盗链配置
把下面这些域名放到白名单里即可,等待几分钟他们就会处理完毕。

图片样式配置

在七牛云“图片样式”里选择好自己所需要的样式,并得到他们给的图片处理接口(由于每个人的需求不同,接口数据也不同,就不一一列出来了)大致样式如下:

WP接入七牛图片样式及防盗链配置

找到主题文件中的“functions.php”,添加下面代码,根据你的情况作出合理修改上传即可,需要注意的是<?/此处为qiniu.com提供的接口>前面的问号是分隔符,如果你设置的是其他符合,例如感叹号之类的需要替换本文提供的问号

//七牛图片处理 www.qicaiyun.top
function fa_converse_webp($matches) {
return $matches[1] . $matches['2'] . '?/此处为qiniu.com提供的接口';     //return $matches[1] . $matches['2'] . '?/imageView2/0/format/webp/q/72';本站的接口(仅供参考)
}

function fa_converse_webp_filter($content){
global $post;
$content = preg_replace_callback("/(<img[^>]*src *= *[\"']?)([^\"']*)/i", 'fa_converse_webp' , $content);
return $content;
}

function fa_is_support_webp(){
return strstr($_SERVER['HTTP_ACCEPT'],'image/webp');
}

if ( fa_is_support_webp() ) add_filter('the_content','fa_converse_webp_filter');

WP接入七牛图片样式及防盗链配置


七彩云博客 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:WP接入七牛图片样式及防盗链配置
喜欢 (0)
[[email protected]]
分享 (0)
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
(7)个小伙伴在吐槽
  1. Residential Rehab Facilities http://aaa-rehab.com Alcohol Rehab Near Me Free Drug Rehab Near Me http://p1spb.ru/user/rehabcenters/
    Substance Abuse Clinics Near Me2020-04-01 17:15 (5天前)回复 Windows 7 | Chrome 66.0.3359.181
  2. Inpatient Drug Rehab Facilities Near Me http://aaa-rehab.com Drug Rehab Drug Rehabilitation Programs Near Me https://puk.chitanka.info/user/rehabcenters/
    Free Inpatient Drug Rehab Centers Near Me2020-04-01 01:20 (6天前)回复 Windows 7 | Chrome 67.0.3396.87
  3. Inpatient Drug Rehab Facilities Near Me http://aaa-rehab.com Drug Rehab Drug Rehabilitation Programs Near Me https://puk.chitanka.info/user/rehabcenters/
    Free Inpatient Drug Rehab Centers Near Me2020-04-01 01:20 (6天前)回复 Windows 7 | Chrome 67.0.3396.87
  4. Cdc Substance Abuse http://aaa-rehab.com Drug Rehab Centers Near Me Alcohol Rehab Facilities Near Me http://pooyeshideh.ir/index.php?subaction=userinfo&user=rehabcenters
    Drug Rehabs That Take Medicaid2020-03-31 08:58 (6天前)回复 Windows 10 | Chrome 67.0.3396.99
  5. Inpatient Drug Treatment Centers Near Me http://aaa-rehab.com Drug Rehab Alcohol Rehab Cost http://demo-market.datalifeengine.ir/user/rehabcenter/
    Free Substance Abuse Counseling2020-03-30 17:03 (7天前)回复 Windows 7 | Chrome 66.0.3359.170
  6. Inpatient Drug Treatment Centers Near Me http://aaa-rehab.com Drug Rehab Alcohol Rehab Cost http://demo-market.datalifeengine.ir/user/rehabcenter/
    Free Substance Abuse Counseling2020-03-30 17:03 (7天前)回复 Windows 7 | Chrome 66.0.3359.170
  7. Residential Alcohol Rehab http://aaa-rehab.com Drug Rehab http://aaa-rehab.com Inpatient Substance Abuse http://aaa-rehab.com
    Inpatient Alcohol Rehab Centers Near Me2020-03-27 10:04 回复 Windows 10 | Chrome 68.0.3440.106