Skip to content

Commit

Permalink
Remove cookieless domain functionality (#13)
Browse files Browse the repository at this point in the history
Since HTTP/2 the cookieless domain functionality is no longer required. Also, remove EOL PHP versions from test suite and add PHP 7.3 for versions that can handle it.
  • Loading branch information
fuegas authored Apr 16, 2019
1 parent 18b4071 commit edb7f4e
Show file tree
Hide file tree
Showing 15 changed files with 33 additions and 706 deletions.
33 changes: 29 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
language: php

php:
- '5.6'
- '7.0'
- '7.1'
- '7.2'
- 7.1
- 7.2
- 7.3

env:
global:
Expand All @@ -13,6 +12,9 @@ env:
- TZ=Europe/Amsterdam
matrix:
- WP_VERSION=latest
- WP_VERSION=5.1.X
- WP_VERSION=5.0.X
- WP_VERSION=4.9.X
- WP_VERSION=4.8.X
- WP_VERSION=4.7.X
- WP_VERSION=4.6.X
Expand All @@ -23,6 +25,29 @@ env:
- WP_VERSION=4.1.X
- WP_VERSION=4.0.X

matrix:
exclude:
- php: 7.3
env: WP_VERSION=4.9.X
- php: 7.3
env: WP_VERSION=4.8.X
- php: 7.3
env: WP_VERSION=4.7.X
- php: 7.3
env: WP_VERSION=4.6.X
- php: 7.3
env: WP_VERSION=4.5.X
- php: 7.3
env: WP_VERSION=4.4.X
- php: 7.3
env: WP_VERSION=4.3.X
- php: 7.3
env: WP_VERSION=4.2.X
- php: 7.3
env: WP_VERSION=4.1.X
- php: 7.3
env: WP_VERSION=4.0.X

before_script:
- composer install
- export PATH="./vendor/bin:$PATH"
Expand Down
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ The full page cache can be flushed from another plugin by using:
do_action( 'warpdrive_cache_flush' ); // This will flush the entire cache
do_action( 'warpdrive_domain_flush' ); // This will only flush the cache of the current domain

### CDN link rewriter
The CDN link rewriter scans html output and rewrites file URI's to the CDN URI.
File extensions which are rewritten are: css, js, gif, png, jpg, ico, ttf, otf, woff.
This is not a real [CDN](https://en.wikipedia.org/wiki/Content_delivery_network) but a cookieless domain to reduce the size of the requests.

### Read logs
From within WordPress on the Warpdrive dashboard there are links to see the last 10/100 entries in the access or error log entries.

Expand Down
1 change: 0 additions & 1 deletion src/class-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ function cache_flush( $domain = '' ) {
$request['body'] = wp_json_encode( [
'domains' => [
$domain,
Options::cdn_domain(),
],
] );
}
Expand Down
46 changes: 0 additions & 46 deletions src/class-cdn-link-rewriter-plugin.php

This file was deleted.

76 changes: 0 additions & 76 deletions src/class-cdn-link-rewriter.php

This file was deleted.

6 changes: 0 additions & 6 deletions src/class-options.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ class Options {
**************************************************/

const CACHING_STYLE = 'warpdrive.caching_style';
const CDN_ENABLE = 'warpdrive.cdn_enabled';
const CDN_DOMAIN_FORMAT = 'cdn.%s.savviihq.com';
const REPO_LOCATION = 'https://github.com/Savvii/warpdrive';
const REPO_RELEASES_LOCATION = 'https://api.github.com/repos/Savvii/warpdrive/releases/latest';

Expand All @@ -37,8 +35,4 @@ public static function access_token() {
public static function system_name() {
return getenv( 'WARPDRIVE_SYSTEM_NAME' );
}

public static function cdn_domain() {
return sprintf( self::CDN_DOMAIN_FORMAT, self::system_name() );
}
}
85 changes: 2 additions & 83 deletions src/class-savvii-dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ class SavviiDashboard {
const FORM_CACHE_SET_DEFAULT = 'warpdrive_cache_set_default';
const FORM_CACHE_USE_DEFAULT = 'warpdrive_cache_use_default';
const FORM_DEFAULT_CACHE_STYLE = 'warpdrive_default_cache_style';
const FORM_CDN_ENABLE = 'warpdrive_cdn_enable';
const FORM_CDN_DEFAULT = 'warpdrive_cdn_default';
const FORM_CDN_SET_DEFAULT = 'warpdrive_cdn_set_default';
const FORM_CDN_USE_DEFAULT = 'warpdrive_cdn_use_default';
const FORM_CDN_HOME_URL = 'warpdrive_cdn_home_url';

/**
* CacheFlusher instance
Expand Down Expand Up @@ -69,28 +64,6 @@ function maybe_update_caching_style() {
update_option( Options::CACHING_STYLE, ( CacheFlusherPlugin::CACHING_STYLE_NORMAL === $_POST[ self::FORM_CACHE_STYLE ] ? CacheFlusherPlugin::CACHING_STYLE_NORMAL : CacheFlusherPlugin::CACHING_STYLE_AGRESSIVE ) );
}

function maybe_update_cdn_enable() {
if ( ! isset( $_POST[ self::FORM_CDN_DEFAULT ] ) ) {
return;
}

check_admin_referer( Options::CDN_ENABLE );

if ( isset( $_POST[ self::FORM_CDN_USE_DEFAULT ] ) ) {
delete_option( Options::CDN_ENABLE );
}

if ( ! isset( $_POST[ self::FORM_CDN_USE_DEFAULT ] ) ) {
update_option( Options::CDN_ENABLE, isset( $_POST[ self::FORM_CDN_ENABLE ] ) ? true : 0 );
}

if ( $this->cache_flusher->flush() ) {
?><div class="updated"><p>Content Delivery Network option saved and performed cache flush.</p></div><?php
} else {
?><div class="error"><p>Content Delivery Network option saved but could not perform cache flush.</p></div><?php
}
}

function maybe_update_default_caching_style() {
if ( ! isset( $_POST[ self::FORM_CACHE_SET_DEFAULT ] ) ) {
return;
Expand All @@ -101,37 +74,17 @@ function maybe_update_default_caching_style() {
update_site_option( Options::CACHING_STYLE, ( CacheFlusherPlugin::CACHING_STYLE_NORMAL === $_POST[ self::FORM_CACHE_SET_DEFAULT ] ? CacheFlusherPlugin::CACHING_STYLE_NORMAL : CacheFlusherPlugin::CACHING_STYLE_AGRESSIVE ) );
}

function maybe_update_default_cdn_enable() {
if ( ! isset( $_POST[ self::FORM_CACHE_SET_DEFAULT ] ) ) {
return;
}

check_admin_referer( Options::CACHING_STYLE );

update_site_option( Options::CDN_ENABLE, isset( $_POST[ self::FORM_CDN_SET_DEFAULT ] ) ? true : 0 );

if ( $this->cache_flusher->flush() ) {
?><div class="updated"><p>Default Content Delivery Network option saved and performed cache flush.</p></div><?php
} else {
?><div class="error"><p>Default Content Delivery Network option saved but could not perform cache flush.</p></div><?php
}
}

function warpdrive_dashboard() {
if ( ! empty( $_POST ) ) {
// Update settings when needed
$this->maybe_update_caching_style();
$this->maybe_update_cdn_enable();
// Update default settings when needed
$this->maybe_update_default_caching_style();
$this->maybe_update_default_cdn_enable();
}

// Get settings from options
$default_cache_style = get_site_option( Options::CACHING_STYLE, CacheFlusherPlugin::get_default_cache_style() );
$default_cdn_enabled = get_site_option( Options::CDN_ENABLE, false );
$cache_style = get_option( Options::CACHING_STYLE, $default_cache_style );
$cdn_enabled = get_option( Options::CDN_ENABLE, $default_cdn_enabled );

$caching_styles = [
CacheFlusherPlugin::CACHING_STYLE_AGRESSIVE => 'Flush on post/page edit or publish',
Expand Down Expand Up @@ -184,36 +137,8 @@ function warpdrive_dashboard() {
</div>
</div>
<!-- /Caching -->
<!-- CDN -->
<div class="postbox" style="min-height: 130px;">
<h2 class="hndle">Content Delivery Network</h2>
<div class="inside">
<div class="main">
<form action="" method="post">
<div class="activity-block">
<div class="button-group-vertical" style="width: 100%;">
<?php if ( is_multisite() ) : ?>
<label class="checkbox"><input type="checkbox" name="<?php echo esc_attr( self::FORM_CDN_USE_DEFAULT ); ?>" <?php echo is_null( get_option( Options::CDN_ENABLE, null ) ) ? 'checked="checked"' : ''; ?> /> Use default network value</label>
<?php endif; ?>
<?php if ( ! is_multisite() || ! is_null( get_option( Options::CDN_ENABLE, null ) ) ) : ?>
<label class="checkbox"><input type="checkbox" name="<?php echo esc_attr( self::FORM_CDN_ENABLE ); ?>" <?php echo $cdn_enabled ? 'checked="checked"' : ''; ?> /> CDN enabled</label>
<?php endif; ?>
</div>
</div>
<input type="hidden" name="<?php echo esc_attr( self::FORM_CDN_DEFAULT ); ?>" value="<?php echo esc_attr( $cdn_enabled ); ?>" />
<?php wp_nonce_field( Options::CDN_ENABLE ); ?>
</form>
</div>
<?php if ( is_ssl() ) : ?>
<div class="sub">
Our CDN does not work in combination with SSL. <a href="https://www.savvii.eu/blog/what-does-the-savvii-content-delivery-network-do/#cdnssl" title="Savvii CDN and SSL" target="_blank">Read here why</a>.
</div>
<?php endif; ?>
</div>
</div>
<!-- /CDN -->
<?php if ( is_multisite() && is_super_admin() ) : ?>
<!-- CDN and caching defaults -->
<!-- Caching defaults -->
<div class="postbox" style="min-height: 130px;">
<h2 class="hndle">Multisite default values (only visible to super admin)</h2>
<div class="inside">
Expand All @@ -229,18 +154,12 @@ function warpdrive_dashboard() {
</select>
</div>
</div>
<h3>Content Delivery Network</h3>
<div class="activity-block">
<div class="button-group-vertical" style="width: 100%;">
<label class="checkbox"><input type="checkbox" name="<?php echo esc_attr( self::FORM_CDN_SET_DEFAULT ); ?>" <?php echo $default_cdn_enabled ? 'checked="checked"' : ''; ?> /> CDN enabled</label>
</div>
</div>
<?php wp_nonce_field( Options::CACHING_STYLE ); ?>
</form>
</div>
</div>
</div>
<!-- /CDN and caching defaults -->
<!-- /Caching defaults -->
<?php endif; ?>
<!-- Read server logs -->
<div class="postbox" style="min-height: 150px;">
Expand Down
6 changes: 0 additions & 6 deletions src/class-warpdrive.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,5 @@ public static function load_modules() {
new CacheFlusherPlugin();
// Include read logs
new ReadLogsPlugin();

// Only load CDN when we want to
$default_cdn_option = get_site_option( Options::CDN_ENABLE, false );
if ( ! is_ssl() && get_option( Options::CDN_ENABLE, $default_cdn_option ) ) {
new CdnLinkRewriterPlugin();
}
}
}
2 changes: 1 addition & 1 deletion tests/install-wp-tests.bash
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ if [[ $WP_VERSION =~ ([0-9]+\.[0-9]+)\.X ]]; then
for ((;; ((PATCH_NUMBER=PATCH_NUMBER+1)))); do
# Test if a download can be found for PATCH_NUMBER
WP_VERSION_TEST="${WP_VERSION_BASE}.${PATCH_NUMBER}"
WP_TEST_RESULT="$(curl -I --silent https://codeload.github.com/WordPress/WordPress/tar.gz/${WP_VERSION_TEST} | head -n 1 | awk '{print $2}')"
WP_TEST_RESULT="$(curl -I --silent https://wordpress.org/wordpress-${WP_VERSION_TEST}.tar.gz | head -n 1 | awk '{print $2}')"
echo "${WP_VERSION_TEST}: ${WP_TEST_RESULT}"
# Break out if the download could not be found
if [ "${WP_TEST_RESULT}" -gt '200' ]; then
Expand Down
2 changes: 1 addition & 1 deletion tests/savvii/class-api-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function test_cache_flush_domain() {
'Authorization' => 'Token token="' . $token . '"',
'Content-Type' => 'application/json',
],
'body' => '{"domains":["example.org","cdn.FooBar.savviihq.com"]}',
'body' => '{"domains":["example.org"]}',
]
)
);
Expand Down
Loading

0 comments on commit edb7f4e

Please sign in to comment.