Skip to content

Commit

Permalink
Merge pull request #203 from wp-media/branch/2.8.20
Browse files Browse the repository at this point in the history
2.8.20
  • Loading branch information
GeekPress authored Oct 13, 2016
2 parents 0f16f34 + 78d858b commit 49fd3a2
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 49 deletions.
114 changes: 67 additions & 47 deletions inc/functions/cloudflare.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@
function get_rocket_cloudflare_instance() {
$cf_email = get_rocket_option( 'cloudflare_email', null );
$cf_api_key = ( defined( 'WP_ROCKET_CF_API_KEY' ) ) ? WP_ROCKET_CF_API_KEY : get_rocket_option( 'cloudflare_api_key', null );

if ( isset( $cf_email, $cf_api_key ) ) {
$cf_instance = ( object ) [ 'auth' => new Cloudflare\Api( $cf_email, $cf_api_key ) ];

try {
$zone_instance = new CloudFlare\Zone( $cf_instance->auth );
$cf_domain = get_rocket_option( 'cloudflare_domain', null );
$zone = $zone_instance->zones( $cf_domain );

if ( isset( $zone->result[0]->id ) ) {
$cf_instance->zone_id = $zone->result[0]->id;
$cf_instance->zone_id = $zone->result[0]->id;
return $cf_instance;
}
} catch ( Exception $e ) {}
Expand All @@ -45,30 +45,34 @@ function get_rocket_cloudflare_instance() {
* @since 2.8.16 Update to CloudFlare API v4
* @since 2.5
*
* @return Array
* @return Array
*/
function get_rocket_cloudflare_settings() {
if( ! is_object( $GLOBALS['rocket_cloudflare'] ) ) {
if ( ! is_object( $GLOBALS['rocket_cloudflare'] ) ) {
return false;
}

$cf_settings_instance = new CloudFlare\Zone\Settings( $GLOBALS['rocket_cloudflare']->auth );
$cf_settings = $cf_settings_instance->settings( $GLOBALS['rocket_cloudflare']->zone_id );
$cf_minify = $cf_settings->result[16]->value;
$cf_minify_value = 'on';

if ( $cf_minify->js === 'off' || $cf_minify->css === 'off' || $cf_minify->html === 'off' ) {
$cf_minify_value = 'off';

try {
$cf_settings_instance = new CloudFlare\Zone\Settings( $GLOBALS['rocket_cloudflare']->auth );
$cf_settings = $cf_settings_instance->settings( $GLOBALS['rocket_cloudflare']->zone_id );
$cf_minify = $cf_settings->result[16]->value;
$cf_minify_value = 'on';

if ( $cf_minify->js === 'off' || $cf_minify->css === 'off' || $cf_minify->html === 'off' ) {
$cf_minify_value = 'off';
}

$cf_settings_array = array(
'cache_level' => $cf_settings->result[5]->value,
'minify' => $cf_minify_value,
'rocket_loader' => $cf_settings->result[25]->value,
'browser_cache_ttl' => $cf_settings->result[3]->value
);

return $cf_settings_array;
} catch ( Exception $e ) {
return false;
}

$cf_settings_array = array(
'cache_level' => $cf_settings->result[5]->value,
'minify' => $cf_minify_value,
'rocket_loader' => $cf_settings->result[25]->value,
'browser_cache_ttl' => $cf_settings->result[3]->value
);

return $cf_settings_array;
}

/**
Expand All @@ -80,7 +84,7 @@ function get_rocket_cloudflare_settings() {
* @return void
*/
function set_rocket_cloudflare_devmode( $mode ) {
if( ! is_object( $GLOBALS['rocket_cloudflare'] ) ) {
if ( ! is_object( $GLOBALS['rocket_cloudflare'] ) ) {
return false;
}

Expand All @@ -90,8 +94,10 @@ function set_rocket_cloudflare_devmode( $mode ) {
$value = 'on';
}

$cf_settings = new CloudFlare\Zone\Settings( $GLOBALS['rocket_cloudflare']->auth );
$cf_settings->change_development_mode( $GLOBALS['rocket_cloudflare']->zone_id, $value );
try {
$cf_settings = new CloudFlare\Zone\Settings( $GLOBALS['rocket_cloudflare']->auth );
$cf_settings->change_development_mode( $GLOBALS['rocket_cloudflare']->zone_id, $value );
} catch ( Exception $e ) {}
}

/**
Expand All @@ -103,12 +109,14 @@ function set_rocket_cloudflare_devmode( $mode ) {
* @return void
*/
function set_rocket_cloudflare_cache_level( $mode ) {
if( ! is_object( $GLOBALS['rocket_cloudflare'] ) ) {
if ( ! is_object( $GLOBALS['rocket_cloudflare'] ) ) {
return false;
}

$cf_settings = new CloudFlare\Zone\Settings( $GLOBALS['rocket_cloudflare']->auth );
$cf_settings->change_cache_level( $GLOBALS['rocket_cloudflare']->zone_id, $mode );

try {
$cf_settings = new CloudFlare\Zone\Settings( $GLOBALS['rocket_cloudflare']->auth );
$cf_settings->change_cache_level( $GLOBALS['rocket_cloudflare']->zone_id, $mode );
} catch ( Exception $e ) {}
}

/**
Expand All @@ -120,7 +128,7 @@ function set_rocket_cloudflare_cache_level( $mode ) {
* @return void
*/
function set_rocket_cloudflare_minify( $mode ) {
if( ! is_object( $GLOBALS['rocket_cloudflare'] ) ) {
if ( ! is_object( $GLOBALS['rocket_cloudflare'] ) ) {
return false;
}

Expand All @@ -129,9 +137,11 @@ function set_rocket_cloudflare_minify( $mode ) {
'html' => $mode,
'js' => $mode
);

$cf_settings = new CloudFlare\Zone\Settings( $GLOBALS['rocket_cloudflare']->auth );
$cf_settings->change_minify( $GLOBALS['rocket_cloudflare']->zone_id, $cf_minify_settings );

try {
$cf_settings = new CloudFlare\Zone\Settings( $GLOBALS['rocket_cloudflare']->auth );
$cf_settings->change_minify( $GLOBALS['rocket_cloudflare']->zone_id, $cf_minify_settings );
} catch ( Exception $e ) {}
}

/**
Expand All @@ -143,12 +153,14 @@ function set_rocket_cloudflare_minify( $mode ) {
* @return void
*/
function set_rocket_cloudflare_rocket_loader( $mode ) {
if( ! is_object( $GLOBALS['rocket_cloudflare'] ) ) {
if ( ! is_object( $GLOBALS['rocket_cloudflare'] ) ) {
return false;
}

$cf_settings = new CloudFlare\Zone\Settings( $GLOBALS['rocket_cloudflare']->auth );
$cf_settings->change_rocket_loader( $GLOBALS['rocket_cloudflare']->zone_id, $mode );

try {
$cf_settings = new CloudFlare\Zone\Settings( $GLOBALS['rocket_cloudflare']->auth );
$cf_settings->change_rocket_loader( $GLOBALS['rocket_cloudflare']->zone_id, $mode );
} catch ( Exception $e ) {}
}

/**
Expand All @@ -159,12 +171,14 @@ function set_rocket_cloudflare_rocket_loader( $mode ) {
* @return void
*/
function set_rocket_cloudflare_browser_cache_ttl( $mode ) {
if( ! is_object( $GLOBALS['rocket_cloudflare'] ) ) {
if ( ! is_object( $GLOBALS['rocket_cloudflare'] ) ) {
return false;
}

$cf_settings = new CloudFlare\Zone\Settings( $GLOBALS['rocket_cloudflare']->auth );
$cf_settings->change_browser_cache_ttl( $GLOBALS['rocket_cloudflare']->zone_id, $mode );

try {
$cf_settings = new CloudFlare\Zone\Settings( $GLOBALS['rocket_cloudflare']->auth );
$cf_settings->change_browser_cache_ttl( $GLOBALS['rocket_cloudflare']->zone_id, $mode );
} catch ( Exception $e ) {}
}

/**
Expand All @@ -176,12 +190,14 @@ function set_rocket_cloudflare_browser_cache_ttl( $mode ) {
* @return void
*/
function rocket_purge_cloudflare() {
if( ! is_object( $GLOBALS['rocket_cloudflare'] ) ) {
if ( ! is_object( $GLOBALS['rocket_cloudflare'] ) ) {
return false;
}

$cf_cache = new CloudFlare\Zone\Cache( $GLOBALS['rocket_cloudflare']->auth );
$cf_cache->purge( $GLOBALS['rocket_cloudflare']->zone_id, true );

try {
$cf_cache = new CloudFlare\Zone\Cache( $GLOBALS['rocket_cloudflare']->auth );
$cf_cache->purge( $GLOBALS['rocket_cloudflare']->zone_id, true );
} catch ( Exception $e ) {}
}

/**
Expand All @@ -196,6 +212,10 @@ function rocket_get_cloudflare_ips() {
return false;
}

$cf_ips_instance = new CloudFlare\IPs( $GLOBALS['rocket_cloudflare']->auth );
return $cf_ips_instance->ips();
try {
$cf_ips_instance = new CloudFlare\IPs( $GLOBALS['rocket_cloudflare']->auth );
return $cf_ips_instance->ips();
} catch ( Exception $e ) {
return false;
}
}
4 changes: 2 additions & 2 deletions wp-rocket.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: WP Rocket
Plugin URI: https://wp-rocket.me
Description: The best WordPress performance plugin.
Version: 2.8.19
Version: 2.8.20
Code Name: Ilum
Author: WP Media
Contributors: Jonathan Buttigieg, Julio Potier, Remy Perona
Expand All @@ -19,7 +19,7 @@
defined( 'ABSPATH' ) or die( 'Cheatin’ uh?' );

// Rocket defines
define( 'WP_ROCKET_VERSION' , '2.8.19' );
define( 'WP_ROCKET_VERSION' , '2.8.20' );
define( 'WP_ROCKET_PRIVATE_KEY' , false );
define( 'WP_ROCKET_SLUG' , 'wp_rocket_settings' );
define( 'WP_ROCKET_WEB_MAIN' , 'http://support.wp-rocket.me/' );
Expand Down

0 comments on commit 49fd3a2

Please sign in to comment.