=== CDNShark CDN – Cache Purge & Real Visitor IP ===
Contributors: cdnshark
Tags: cdn, cache, purge, real ip, performance
Requires at least: 6.4
Tested up to: 7.1
Requires PHP: 7.4
Stable tag: 1.0.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

For sites proxied through CDNShark: clears the CDN cache when content changes, and shows WordPress the real visitor IP instead of the CDN's.

== Description ==

When your site runs behind the CDNShark CDN, pages are served from CDNShark's edge servers around the world. This plugin keeps those copies up to date and makes sure WordPress still knows who your visitors are.

**Automatic purging**

* Publish, update, unpublish or delete a post, page or product: that page is cleared from the CDN, together with the home page, your feeds and the category, tag and author pages it appears on.
* A comment is approved, edited or removed: that post's page is cleared.
* WooCommerce stock changes (after an order, for example): the product page is cleared, so visitors do not see "in stock" for something that sold out.
* Theme, menus, widgets, Customizer or permalinks change, or plugins, themes or WordPress are updated: the whole site is cleared, because these show on every page.

Exact pages are cleared in seconds. A whole-site purge reaches every CDNShark edge within 10–30 seconds. Purges are sent after your page has been saved, so the editor never waits for them.

**Purge buttons**

"Purge everything" on the settings page and in the admin bar, and "Purge this page" in the admin bar while you view your site.

**Real visitor IP**

Behind a CDN, every request reaches WordPress from a CDN server. Login limiters, security plugins and comment-spam filters then see one address for everybody. Turn on "Real visitor IP" and WordPress sees each visitor's own address again. The address passed by CDNShark is only trusted when the request really comes from one of CDNShark's published edge servers (https://cdnshark.com/ips.json), so nobody can fake it.

**Logged-in visitors**

CDNShark never serves cached pages to logged-in users, people with something in their WooCommerce cart, or visitors who unlocked a password-protected post. That is handled by the CDN itself, with or without this plugin.

**What you need**

A CDNShark account with your domain proxied through CDNShark, and an API token with only "Cache purge" ticked (CDNShark portal → API Tokens). Such a token can do nothing except clear the cache of the domains you pick, which is what you want for a token stored in a website's database.

== External services ==

This plugin connects to CDNShark (https://cdnshark.com), the CDN your site runs behind:

* When you save the settings, it sends your API token to https://cdnshark.com/api/purge/scope to check which domains it may purge.
* When content changes or you press a purge button, it sends the addresses of the affected pages to https://cdnshark.com/api/domains/{your-domain}/purge.
* With "Real visitor IP" on, it downloads the list of CDNShark edge addresses from https://cdnshark.com/ips.json once a day. This request sends nothing about your site or visitors.

No visitor data is sent to CDNShark by the plugin. CDNShark terms: https://cdnshark.com/policy/terms. Privacy policy: https://cdnshark.com/policy/privacy.

== Installation ==

**1. Put your domain on CDNShark**

1. In the CDNShark portal open **CDN → Domains** and click **Add Domain**. If you have no CDN plan yet, pick one on the same screen.
2. At your domain registrar, change the nameservers to the ones shown on your domains list.
3. In **CDN → DNS Zone**, make sure the records your site uses (usually the domain itself and `www`) have **Is Proxy** and **Is Cached** ticked.

**2. Create a purge-only token**

1. In the portal open **Developer Tools → API Tokens**.
2. Give the token a name, for example "WordPress".
3. Tick only **Cache purge**, then pick your site's domain in the list that appears.
4. Click **Create token** and copy it. It is shown only once.

**3. Install the plugin and connect it**

1. Install and activate the plugin.
2. Open **Settings → CDNShark CDN**, paste the token and click **Save Changes**.
3. The page should say "Connected: this site is part of example.com on CDNShark". If it shows an error instead, it says what to fix.
4. Optional: tick **Real visitor IP** and save.

The token can also be set in wp-config.php instead: `define( 'CDNSHARK_CDN_TOKEN', 'your-token' );`

== Frequently Asked Questions ==

= Do I need a CDNShark account? =

Yes. The plugin manages the cache of a site that is proxied through CDNShark; without that there is nothing for it to do.

= Why a "Cache purge" token and not a full API token? =

The token is stored in your WordPress database. A purge-only token cannot read or change anything in your CDNShark account; at worst it can clear your cache.

= My page still shows the old version =

Check the "Recent purges" list on the settings page. If the purge succeeded, your browser may still have its own copy: reload with Ctrl+F5 (Cmd+Shift+R on a Mac).

= Does it rewrite my image or script URLs? =

No. Your whole domain is served through CDNShark, so nothing needs to be rewritten.

== Changelog ==

= 1.0.0 =
* First release.
