# Full Site Cache Enabler for KeyCDN

Make all HTML page on CDN cache, optimize your website speed. Make your site superfast.

## Description

This plugin can help you to use KeyCDN on your WordPress, not only your Media and CSS, but also all HTML page. This plugins can automatically purge the page that need to update, when you publish a page or post.

Require:

+ PHP 5.4+
+ Wordpress 4.4+ (I only tested it on 4.4+)

## Installation

Before use this plugin, you need to have a KeyCDN account. You can [sign up by this link](https://www.keycdn.com/?a=7126), and you can get $10 free credit, that is included 250GB web traffic, it's enough for your test, and can use for a long time (if you have not too much web traffic).

Put the folder `full-site-cache-kc` in your server, to `wp-content/plugins/full-site-cache-kc/`, you can [download it at here](https://wordpress.org/plugins/full-site-cache-kc/).

Or if you can add plugin online, you can search `full-site-cache-kc` and install it.

After that, you need to finish those setup and configuration step by step, following the introduction below.

### 1. Setup KeyCDN

You need to add a `Pull Zone` in KeyCDN, and set `Origin URL` to `http(s)://[The IP of your server]`, set SSL to `Letsencrypt` (You can get free SSL support!), enable `Cache Cookies`, `Strip Cookies` and `Forward Host Header`. Set `Expire (in minutes)` to -1 and set `Max Expire (in minutes)` to 1440 or bigger, and make sure to disable `CORS`.

### 2. Setup DNS

You need to use a domain like `www.example.com` or `blog.example.com` but not root domain like `example.com`, because you need to create a CNAME on that domain.

If you are using domain like `www.example.com`, you need to create a DNS at `wp-admin.example.com` that point to your server.

If you are using domain like `blog.example.com`, you need to create a DNS at `wp-admin-blog.example.com` that point to your server.

After you setted up, you need to go to the new host to visit WordPress dashboard.

### 3. Setup this plugin

Add these code at the top of `wp-config.php`., just after `<?php`

!!! NOTE: it's PRETTY DANGEROUS to change `wp-config.php` file and add function `require_once`, make sure you had already backup your WordPress, and if you are not a programmer, I highly recommend you do not change `wp-config.php` until you know something about PHP script !!!

```php
$fsckeycdn_useHTTPS = false; // Change it to true if your server support HTTPS.
$fsckeycdn_x_pull_key = 'KeyCDN'; // By default is `KeyCDN`, to make your server more secure, change it to a random 15 alphameric key, and update KeyCDN Zone settings.

/* Set white list, if the IP is not in this white list and not KeyCDN, show `403 Forbidden`, if you don't use proxy server, delete these three lines */
$fsckeycdn_ip_white_list =[
	'103.21.244.0/22',
	'103.22.200.0/22',
	'103.31.4.0/22',
	'104.16.0.0/12',
	'108.162.192.0/18',
	'131.0.72.0/22',
	'141.101.64.0/18',
	'162.158.0.0/15',
	'172.64.0.0/13',
	'173.245.48.0/20',
	'188.114.96.0/20',
	'190.93.240.0/20',
	'197.234.240.0/22',
	'198.41.128.0/17',
	'199.27.128.0/21'
]; // This is CloudFlare's IP. If you are not use CloudFlare, change it to your server. IPv4 and IPv4 range are both supported. If the IPs are private ip, just set it to `[]`.
$fsckeycdn_client_ip = $_SERVER['HTTP_X_CLIENT_IP']; // The IP for your proxy server
$fsckeycdn_client_real_ip = $_SERVER['HTTP_CF_CONNECTING_IP']; // The IP for real client (Optional), this is for CloudFlare

require_once(ABSPATH . 'wp-content/plugins/full-site-cache-kc/include.php'); // This plugin need run some scripts before everything, so you need to add this, if you use a different location for plugins, change it.
```

Then add some configuration variable at anywhere of `wp-config.php`.

```php
// sets up KeyCDN
$fsckeycdn_apikey = 'vHlnpHcE6GPEWyTWWisr4hE9e80Xvr4a';
$fsckeycdn_url = [
	1 => [
		'id' => 10001,
		'name' => 'www',
	],
	2 => [
		'id' => 10002,
		'name' => 'ze3kr',
	],
	3 => [
		'id' => 10003,
		'name' => 'blog',
	],
];
```

The number (1,2,3) before each small array is blog id. the `id` is KeyCDN.

After that, you can enable this plugin.

### 4. Setup WordPress

If you are using multisite, it's hard to change URL, you need to create a new blog named `www`, and import the old blog to it.

When you finished `Setup this plugin`, it will automatically redirect non-www to www domain.

And you need to change Siteurl to the new domain, keep Home URL not change.

## About purge

This plugin will purge all page that need to be purge, but when your customized your theme or changed your theme, you need to purge your site manually. **We highly recommend you just purge tag `wordpress`**, instead of purge everything. The tag `wordpress` is include all page that generated by WordPress PHP program, and not include static file like Media, CSS and JS. If you purge everything, that will slow down your website and make more request to your orgin server.

## Known Issues

+ Customize page can't show preview.
+ Customize page can't set widgets, if you want to set, goto `/wp-admin/widgets.php`.

## Frequently Asked Questions

### It takes a long time to publish a long time to publish a post or page?

That is because this plugin will purge the cache immediately, and that need to send a request to KeyCDN server. It very depend on your network and KeyCDN network

## Changelog

## 0.3.1

+ Disallow Direct File Access to plugin files.
+ Use Unique function (and/or define) names.

## Upgrade Notice

## 0.3.1

This update changed some function name and variable name, you need to edit `wp-config.php`.
