WordPress无需插件纯代码实现将网站静态资源

代码 代码 1526 人阅读 | 0 人回复

<
WordPress七牛镜存储插件,WP SUPER CACHE的CDN功用,皆是能够经由过程代码完成的。The Qiniu mirror storage plug-in and the CDN function of WP SUPER CACHE can all be implemented by code.
The first step is to upload the wp-content and wp-includes directories in your blog to the object storage of Qiniu or YouPaiyun, Tencent Cloud, and Alibaba Cloud. The second step is to upload the files, and modify the website address in the following code Become your blog domain name (note: do not add / at the end) cdn domain name is changed to the domain name bound to the object storage, fill in the default domain name (note: do not add / at the end), and then put the following code into the theme’s functions.php file At the bottom of the web site URL domain name setting acceleration directory setting file whitelist}{);}}}}}}}}}}}}}}}}}}

WordPress无需插件杂代码完成将网站静态资本

WordPress无需插件杂代码完成将网站静态资本
第一步
把您专客里的wp-content战wp-includes目次上传到七牛或又拍云、腾讯云、阿里云的工具存储中
第两步
上传文件完以后,将以下代码中的网站地点修正成您的专客域名(注:末端没有要减 / )cdn域名修正成工具存储绑定的域名出有便挖默许的域名(注:末端没有要减 / ),然后将以下代码放进主题的functions.php文件中最底部便可
define('FocusCDNHost','http://www.31du.cn');//wordpress网站网址define('FocusCDNRemote','http://cdn.31du.cn');//cdn域名define('FocusCDNIncludes','wp-content,wp-includes');//设置加快目次define('FocusCDNExcludes','.php|.xml|.html|.po|.mo');//设置文件利剑名单define('FocusCDNRelative','');//Check this if you want to have links like <wp-content/abc.png> rewritten - i.e. without your blog's domain as prefix.function do_cdnrewrite_ob_start() {$rewriter = new FocusCDNRewriteWordpress();$rewriter->register_as_output_buffer();}add_action('template_redirect', 'do_cdnrewrite_ob_start');class FocusCDNRewriteWordpress extends FocusCDNRewrite{function __construct() {$excl_tmp = FocusCDNExcludes;$excludes = array_map('trim', explode('|', $excl_tmp));parent::__construct(FocusCDNHost,FocusCDNRemote,FocusCDNIncludes,$excludes,!!FocusCDNRelative);}public function register_as_output_buffer() {if ($this->blog_url != FocusCDNRemote) {ob_start(array(&$this, 'rewrite'));}}}class FocusCDNRewrite {var $blog_url = null;var $cdn_url = null;var $include_dirs = null;var $excludes = array();var $rootrelative = false;function __construct($blog_url, $cdn_url, $include_dirs, array $excludes, $root_relative) {$this->blog_url = $blog_url;$this->cdn_url = $cdn_url;$this->include_dirs = $include_dirs;$this->excludes = $excludes;$this->rootrelative = $root_relative;}protected function exclude_single(&$match) {foreach ($this->excludes as $badword) {if (stristr($match, $badword) != false) {return true;}}return false;}protected function rewrite_single(&$match) {if ($this->exclude_single($match[0])) {return $match[0];} else {if (!$this->rootrelative || strstr($match[0], $this->blog_url)) {return str_replace($this->blog_url, $this->cdn_url, $match[0]);} else {return $this->cdn_url . $match[0];}}}protected function include_dirs_to_pattern() {$input = explode(',', $this->include_dirs);if ($this->include_dirs == '' || count($input) < 1) {return 'wp\-content|wp\-includes';} else {return implode('|', array_map('quotemeta', array_map('trim', $input)));}}public function rewrite(&$content) {$dirs = $this->include_dirs_to_pattern();$regex = '#(?<=[(\"\'])';$regex .= $this->rootrelative? ('(?:'.quotemeta($this->blog_url).')?'): quotemeta($this->blog_url);$regex .= '/(?(?:'.$dirs.')[^\"\')]+)|([^/\"\']+\.[^/\"\')]+))(?=[\"\')])#';return preg_replace_callback($regex, array(&$this, 'rewrite_single'), $content);}}
1、本网站属于个人的非赢利性网站,转载的文章遵循原作者的版权声明,如果原文没有版权声明,按照目前互联网开放的原则,我们将在不通知作者的情况下,转载文章;如果原文明确注明“禁止转载”,我们一定不会转载。如果我们转载的文章不符合作者的版权声明或者作者不想让我们转载您的文章的话,请发帖留言提供原创证明,我们将积极配合您!
2、本网站转载文章仅为传播更多信息之目的,凡在本网站出现的信息,均仅供参考。本网站将尽力确保所提供信息的准确性及可靠性,但不保证信息的正确性和完整性,且不对因信息的不正确或遗漏导致的任何损失或损害承担责任。
3、任何透过本网站网页而链接及得到的资讯、产品及服务,本网站概不负责,亦不负任何法律责任。
4、本网站所刊发、转载的文章,其版权均归原作者所有,如其他媒体、网站或个人从本网下载使用,请在转载有关文章时务必尊重该文章的著作权,保留本网注明的“稿件来源”,并自负版权等法律责任。
回复

使用道具 举报

 
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则