Skip to content

Commit

Permalink
Added: Cloudflare compatibility
Browse files Browse the repository at this point in the history
Added: WP Fastest Cache compatibility
  • Loading branch information
Dan0sz committed Oct 7, 2024
1 parent 693bac6 commit d1ad70e
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 0 deletions.
9 changes: 9 additions & 0 deletions includes/class-compatibility.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,19 @@ private function init() {
new CAOS_Compatibility_Autoptimize();
}

/**
* Always run Cloudflare compatibility, because it doesn't do any harm.
*/
new CAOS_Compatibility_Cloudflare();

if ( defined( 'LSCWP_V' ) ) {
new CAOS_Compatibility_Litespeed();
}

if ( defined( 'WPFC_MAIN_PATH' ) ) {
new CAOS_Compatibility_WpFastestCache();
}

if ( defined( 'WP_ROCKET_VERSION' ) ) {
new CAOS_Compatibility_WpRocket();
}
Expand Down
43 changes: 43 additions & 0 deletions includes/compatibility/class-cloudflare.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/* * * * * * * * * * * * * * * * * * * *
* ██████╗ █████╗ ██████╗ ███████╗
* ██╔════╝██╔══██╗██╔═══██╗██╔════╝
* ██║ ███████║██║ ██║███████╗
* ██║ ██╔══██║██║ ██║╚════██║
* ╚██████╗██║ ██║╚██████╔╝███████║
* ╚═════╝╚═╝ ╚═╝ ╚═════╝ ╚══════╝
*
* @author : Daan van den Bergh
* @url : https://daan.dev/wordpress/caos/
* @copyright: © 2021 - 2024 Daan van den Bergh
* @license : GPL2v2 or later
* * * * * * * * * * * * * * * * * * * */

class CAOS_Compatibility_Cloudflare {
/**
* Build class.
*/
public function __construct() {
$this->init();
}

/**
* Action and filter hooks.
*
* @return void
*/
private function init() {
add_filter( 'caos_script_custom_attributes', [ $this, 'exclude_from_cloudflare' ] );
}

/**
* Add data-no-optimize="1" attribute to script if LiteSpeed Cache is enabled.
*
* @param $attributes
*
* @return string
*/
public function exclude_from_cloudflare( $attributes ) {
return 'data-cfasync="false" ' . $attributes;
}
}
43 changes: 43 additions & 0 deletions includes/compatibility/class-wp-fastest-cache.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/* * * * * * * * * * * * * * * * * * * *
* ██████╗ █████╗ ██████╗ ███████╗
* ██╔════╝██╔══██╗██╔═══██╗██╔════╝
* ██║ ███████║██║ ██║███████╗
* ██║ ██╔══██║██║ ██║╚════██║
* ╚██████╗██║ ██║╚██████╔╝███████║
* ╚═════╝╚═╝ ╚═╝ ╚═════╝ ╚══════╝
*
* @author : Daan van den Bergh
* @url : https://daan.dev/wordpress/caos/
* @copyright: © 2021 - 2024 Daan van den Bergh
* @license : GPL2v2 or later
* * * * * * * * * * * * * * * * * * * */

class CAOS_Compatibility_WpFastestCache {
/**
* Build class.
*/
public function __construct() {
$this->init();
}

/**
* Action and filter hooks.
*
* @return void
*/
private function init() {
add_filter( 'caos_script_custom_attributes', [ $this, 'exclude_from_wpfc' ] );
}

/**
* Add data-no-optimize="1" attribute to script if LiteSpeed Cache is enabled.
*
* @param $attributes
*
* @return string
*/
public function exclude_from_wpfc( $attributes ) {
return 'data-wpfc-render="false" ' . $attributes;
}
}

0 comments on commit d1ad70e

Please sign in to comment.