Created
November 8, 2015 05:54
-
-
Save heiybb/1cd816c4d4cfa618fd3e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** 替换特色图片附件为七牛 **/ | |
/** ?imageView2/1/q/85/format/WEBP 暂时取消对图像进行WEBP处理**/ | |
function QiNiuCDN(){ | |
function Rewrite_URI($html){ | |
/* 前面是需要用到七牛的域名,后面是需要加速的文件类型,使用分隔符 | 隔开即可 */ | |
$pattern ='/http:\/\/heiybb\.com\/wp-content([^"\']*?)\.(jpg|png|jpeg)/i'; | |
/* 七牛CDN空间地址 */ | |
if($is_chrome){ | |
$replacement = 'https://dn-img-blog.qbox.me$1.$2?imageView2/1/q/85/format/WEBP'; | |
} | |
else{ | |
$replacement = 'https://dn-img-blog.qbox.me$1.$2'; | |
} | |
$html = preg_replace($pattern, $replacement,$html); | |
return $html; | |
} | |
/* 如果为管理员则显示原始链接 */ | |
if(!is_admin()){ | |
ob_start("Rewrite_URI"); | |
} | |
} | |
add_action('init', 'QiNiuCDN'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment