| 1 |
<?php |
| 2 |
/** |
| 3 |
* Extension Name: Cloudflare |
| 4 |
* Extension URI: https://poweredcache.com/extensions/cloudflare |
| 5 |
* Description: Cloudflare extension for Powered Cache |
| 6 |
* Author: Powered Cache Team |
| 7 |
* Version: 1.0 |
| 8 |
* Author URI: https://poweredcache.com |
| 9 |
* Extension Image: extension-image.png |
| 10 |
* License: GPLv2 (or later) |
| 11 |
*/ |
| 12 |
|
| 13 |
if ( ! defined( 'ABSPATH' ) ) { |
| 14 |
exit; |
| 15 |
} |
| 16 |
|
| 17 |
require_once 'inc/class-powered-cache-cloudflare-api.php'; |
| 18 |
|
| 19 |
// Fixes Flexible SSL |
| 20 |
if ( isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' ) { |
| 21 |
$_SERVER['HTTPS'] = 'on'; |
| 22 |
} |
| 23 |
|
| 24 |
// real user ip |
| 25 |
if ( isset( $_SERVER['HTTP_CF_CONNECTING_IP'] ) ) { |
| 26 |
$_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_CF_CONNECTING_IP']; |
| 27 |
} |
| 28 |
|
| 29 |
if ( is_admin() ) { |
| 30 |
require_once 'inc/class-powered-cache-cloudflare-admin.php'; |
| 31 |
Powered_Cache_Cloudflare_Admin::factory(); |
| 32 |
} |
| 33 |
|
| 34 |
|
| 35 |
/** |
| 36 |
* Purge cloudflare cache |
| 37 |
* |
| 38 |
* @since 1.0 |
| 39 |
* @return array|bool|mixed|object|string |
| 40 |
*/ |
| 41 |
function powered_cache_cloudflare_purge_cache() { |
| 42 |
$email = powered_cache_get_extension_option( 'cloudflare', 'email' ); |
| 43 |
$api_key = powered_cache_get_extension_option( 'cloudflare', 'api_key' ); |
| 44 |
if ( $email && $api_key ) { |
| 45 |
$api = new Powered_Cache_Cloudflare_Api( $email, $api_key ); |
| 46 |
|
| 47 |
$zone = powered_cache_get_extension_option( 'cloudflare', 'zone' ); |
| 48 |
if ( $zone ) { |
| 49 |
return $api->purge( $zone ); |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
return false; |
| 54 |
} |
| 55 |
|
| 56 |
add_action( 'powered_cache_purge_all_cache', 'powered_cache_cloudflare_purge_cache' ); |
| 57 |
|
| 58 |
// make description translatable |
| 59 |
__( 'Cloudflare extension for Powered Cache', 'powered-cache' ); |
| 60 |
|