Created
January 21, 2016 14:37
-
-
Save wbbim/3ab2f746bb09ed54f2bf to your computer and use it in GitHub Desktop.
wordpress 加速
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
if ( !is_admin() ) { | |
add_action('wp_loaded','c7sky_ob_start'); | |
function c7sky_ob_start() { | |
ob_start('c7sky_qiniu_cdn_replace'); | |
} | |
function c7sky_qiniu_cdn_replace($html){ | |
$local_host = 'https://www.17.tf'; //博客域名 | |
$qiniu_host = 'https://o1b3xtzrf.qnssl.com'; //七牛域名 | |
$cdn_exts = 'js|css|png|jpg|jpeg|gif|ico'; //扩展名(使用|分隔) | |
$cdn_dirs = 'wp-content|wp-includes'; //目录(使用|分隔) | |
$cdn_dirs = str_replace('-', '\-', $cdn_dirs); | |
if ($cdn_dirs) { | |
$regex = '/' . str_replace('/', '\/', $local_host) . '\/((' . $cdn_dirs . ')\/[^\s\?\\\'\"\;\>\<]{1,}.(' . $cdn_exts . '))([\"\\\'\s\?]{1})/'; | |
$html = preg_replace($regex, $qiniu_host . '/$1$4', $html); | |
} else { | |
$regex = '/' . str_replace('/', '\/', $local_host) . '\/([^\s\?\\\'\"\;\>\<]{1,}.(' . $cdn_exts . '))([\"\\\'\s\?]{1})/'; | |
$html = preg_replace($regex, $qiniu_host . '/$1$3', $html); | |
} | |
return $html; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment