当前位置:首页 > WordPress教程代码·功能 > 正文

WordPress非插件使用七牛云存储、又拍云

以前介绍过使用七牛云加速,自我感觉七牛还是蛮不错的。 当然又拍云也可以啦!

关于七牛云存储的好处我们不多说了,它可以把我们网站的css.js.图片等全部放在七牛进行加速

虽然有免费流量的限制但是小站基本上够用,幻杀使用后感觉速度提升还是很明显的。

幻杀使用的插件,是我爱水煮鱼开发的七牛云存储插件,但是使用P3(点击这里查看)进行检测时,显示居然很坑速度,本来我还是很喜欢插件,但是对速度好吧……我不说了。

嗯,这个方法你可以选择用代码的,当然也可以不用代码的,如果都嫌烦那么还是用插件吧 关于

多方法可以选择性共同使用,记住是选择 !选择哟!记住看最后的评论再选择!

七牛云加速-幻杀博客

方法1:

把这个插件代码化,这样就不用插件了。 打开你主题文件中的funsion文件(修改有风险,用前需备份)加入以下代码
//将主题自带的 CSS 和 JS 文件替换成七牛镜像存储
define(‘CDN_HOST’,’http://hsdate.qiniudn.com/’);
add_filter(‘stylesheet_directory_uri’,’dw_cdn_stylesheet_directory_uri’,10,3);
function dw_cdn_stylesheet_directory_uri($stylesheet_dir_uri, $stylesheet, $theme_root_uri) {
return str_replace(home_url(), CDN_HOST, $stylesheet_dir_uri);
}
add_filter(‘template_directory_uri’,’dw_cdn_template_directory_uri’,10,3);
function dw_cdn_template_directory_uri($template_dir_uri, $template, $theme_root_uri) {
return str_replace(home_url(), CDN_HOST, $template_dir_uri);

把里面设置的hsdate.qiniudn.com 地址换成你自己申请的加速域名。七牛又拍应该都有吧!

然后保存刷新下后查看下源代码,发现有关js的域名是不是已经被更改了!

当然这个只可以对你的js 和css进行加速,对图片无效!

方法2:

使用上边方法加速效果不好?一般大家站点js css 数量应该没有图片多,最主要还是加速图片吧

使用这个方法图片也是可以加速的。

所以那使用下面的方法就可以将图片也使用七牛云存储了。

就如这个地址:http://ihuan.me/wp-admin/options.php,然后那找到upload_url_path,使用快捷键 跟方便 别自个凭眼睛慢慢找,你会疯的!

其中 ihuan.me 要换成你自己个博客地址 如果安装在子目录下 将子目录一块弄进去。

找到后 在那项出 添加 http://hsdate.qiniudn.com/wp-content/uploads,然后保存,其中hsdate.qiniudn.com一样换成你自己的。

这时候我们写一篇文章添加一张图片试试,图片的地址是不是已经变为七牛的地址了呢!

方法2有缺陷:就是说图片直接存在七牛的cdn空间上,这个对于网站空间紧张的用户来说是一个不错的选择

但是对于网站空间很充足的来说就不是很爽了,因为七牛毕竟不是自己的空间,我们不可能吧希望全部放在七牛那边,将来如果更换cdn空间的话这些图片有可能就全部无法使用!

简单的说,就是图片将直接上传至七牛空间而不通过你自己的空间! 图片不会在你的空间储存而是直接储存到了七牛!有利有弊,空间小的高兴,空间足的不高兴!

因为方法2没有备份,如果你有需要更换的话,就选择方法3,图片在本地回自动保留一份!

方法3:

define(‘FocusCDNHost’,’http://ihuan.me’);//wordpress网站网址
define(‘FocusCDNRemote’,’http://hsdate.qiniudn.com’);//cdn域名
define(‘FocusCDNIncludes’,’wp-content,wp-includes’);//设置加速目录,可自行输入
define(‘FocusCDNExcludes’,’.php|.xml|.html|.po|.mo’);//设置文件白名单,一样可自行输入
define(‘FocusCDNRelative’,”);
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);
}
}

方法3很高大上,完全可以和插件媲美,准确说和插件差不多了,插件有的他也有,除了七牛那个恶心人的水印木有!

白名单啥的都有了!

根据前面的描述,大体给个使用的说明

方法一,可以只可以加速js css

方法二,可以加速图片等通过上传方式上传的文件,但是缺点是文件没有在本地进行备份而是直接去了七牛!

方法三,可控可存 可以控制文件储存白名单,文件也会在本地有储存!

你可以依据此说明进行一下选择,选择哟,出错咱不管!!!

好了,又可以干掉一个插件,麻麻再也不用怕插件多了!

标签:
上一篇: 下一篇:

818 条评论

评论加载中...
  1. What a information of un-ambiguity and preserveness of valuable know-how regarding
    unpredicted emotions.

    2018年8月20日 17:07 评论
  2. Claire Foy as Janet Shearon, Armstrong’s first wife.

    2018年8月20日 10:33 评论
  3. 806楼
    这家伙可能用了美佬的代理 QQ浏览器 Windows 7
    watch The Grinch  

    I love what you guys are usually up too. This type of clever
    work and exposure! Keep up the amazing works guys I’ve included you guys to my own blogroll.

    2018年8月20日 10:25 评论
  4. A lot of districts are now trying year round programs that still
    give kids time off to do the family stuff that they would do over the summer students put
    in 45 days, then get a 15 day break. So, work nine weeks, play
    three weeks. In that system, the kids are still putting
    in about 180 days, but without the time wasted getting everyone back
    up to speed in the fall.

    Cheap Jerseys from china We don’t NEED these guys from SAHARA.
    They think they are bigger than Indian cricket simply cause the national team wears their name on their jerseys.

    It’s good that the BCCI has had enough of these
    people. One of the great things about taking Defensive
    Driving Course NY, which is a web that is
    all you need is a computer with an Internet connection to access it.
    This gave me the freedom I have to go about my daily life and still be able
    get rid of the ticket, when I had time. If you register
    during the dismissal of the ticket you will be asked to choose
    a user name and password for the account, it how you enter into play every time.Cheap Jerseys from china

    wholesale jerseys from china My grandfather on my mother’s side was an engine driver.
    He was still in work, and he and his associates used to collect old children’s clothes,
    shoes, boots, anything, and pass it on to us. Mother tore apart old woollen jumpers to re knit them as red and white jerseys and stockings for us to play
    football in.”.wholesale jerseys from china

    Cheap Jerseys from china I am more concerned with further ostracizing Black gay and bisexual men. In fact, one might argue that this film given its gaining popularity might set back the advancements that Black gay groups have been making within Black America on this very subject. However, only time will tell on that one..Cheap Jerseys from china

    wholesale nfl jerseys The issue of whether or not purchasing another trademark for use as a Google Adword constitutes trademark infringement has no clear cut answer. As a result of the differing interpretations by the courts, businesses that purchase the trademarks of a competitor in order to trigger Internet advertising are at risk of liability for trademark infringement. Further confusing things, liability may depend on the jurisdiction in which the keyword purchaser is located, at least for the foreseeable future.wholesale nfl jerseys

    Cheap Jerseys from china One of these could be a great help for anyone who lives in a cold town. However, if you are hot getting any major snow storms, an electric snow blowerwill suffice your needs. To find out whether an electric unit would work fine in your state, you have to consider the rate of snowfall where you live..Cheap Jerseys Cheap Jerseys from china from china

    wholesale jerseys from china Whether you are riding an epic Tour de France stage or just off for a pootle around the lanes, there’s a good chance you will carry a bidon, as they say en France. During the Eighties, Italian company Elite provided the Tour de France with thousands of bidons and now, three decades later, continue to supply top teams such as Sky and BMC Racing. Whether or not you load them with water, energy drink or electrolyte solution will depend on how serious you take your riding.wholesale jerseys from china

    cheap jerseys According to the NCAA Division II Manual, the first practice date for the Championship Segment may not occur more than 21 days before the first allowed intercollegiate game or seven days before the first day of classes, whichever is earlier. Division II requires a five day acclimatization period with the same restrictions as Division I. Multiple practices may not be scheduled on consecutive days.cheap jerseys

    Cheap Jerseys free shipping This is similar to the connection between high cholesterol foods and heart disease. Eating high cholesterol foods causes heart disease, especially in people who have family histories of heart disease. In truth, most foods that are in this category, as well as the real culprit is Hydrogenated oil.Cheap Jerseys free shipping

    Later, John Deere improved upon the design of the plow. His plows were of cast steel and greatly helped the Great Plains farmers. These were efficient and cut through the toughest of soils to allow for planting of crops. A special pre game ceremony was held at Fenway Park prior to the Sox game against the Kansas City Royals on the Saturday after the bombs exploded. Sox players wore “BOSTON” jerseys that were autographed and auctioned to benefit the victims. In addition, the Fenway faithful were led in their eighth inning anthem of Sweet Caroline by Neil Diamond..

    wholesale jerseys from china I fully admit that my image of Mountain Brook is one frozen in time, like a specimen in a jar. In recent years, Birmingham has become a popular and thriving place to live, and I am sure the influx of cultures and ethnicities has only helped bring Mountain Brook out of the cotton fields. But there will always be subjects that remain off limits wholesale jerseys from china.

    .

    2018年8月20日 08:51 评论
  5. cheap nfl jerseys Cheap Jerseys from china mvjosg57558

    2018年8月20日 06:28 评论
  6. I just wanted to let you all know that I added a new list. It has taken me awhile to let everyone know due to server issues. Everything should be back on track now.

    2018年8月20日 05:06 评论
  7. Cheap Jerseys from china wholesale jerseys from china itpcul24585

    2018年8月20日 01:32 评论
  8. Way cool! Some extremely valid points! I appreciate you writing this post and also the rest of the website is
    also very good.

    2018年8月20日 01:31 评论

发表评论

不理你。不要啊!吃饭。吃惊。吃西瓜。飞吻!恭喜!Hi纠结!膜拜!OK抛媚眼。泡泡糖。抛钱。忍!生闷气!调皮。偷看。委屈。献花。疑问?抓狂!

小提示:Ctrl+Enter快速提交助您一臂之力~
加载中……