Skip to content

Commit

Permalink
implementing #430 using stateless_skip_cache_busting filter
Browse files Browse the repository at this point in the history
  • Loading branch information
antonkorotkov committed Feb 21, 2020
1 parent ee9f9a5 commit 9f8043d
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions lib/classes/compatibility/divi.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ class Divi extends ICompatibility {
*/
private $cache_busting_disable_conditions = array(
array(
'stack_level' => 4,
'stack_level' => 7,
'function' => '__construct',
'class' => 'ET_Core_PageResource'
),
array(
'stack_level' => 4,
'stack_level' => 7,
'function' => 'get_cache_filename',
'class' => 'ET_Builder_Element'
)
Expand All @@ -53,24 +53,23 @@ public function module_init($sm){
remove_filter( 'sanitize_file_name', array( "wpCloud\StatelessMedia\Utility", 'randomize_filename' ), 10 );
}

// maybe disable the filter
add_filter('sanitize_file_name', array( $this, 'sanitize_file_name' ), 1);
// maybe skip cache busting
add_filter( 'stateless_skip_cache_busting', array( $this, 'maybe_skip_cache_busting' ), 10, 2 );
}

/**
* Check if `sanitize_file_name` filter was called in a place where we don't need our custom filter.
* Remove our 10-priority filter if condition met.
* Maybe skip cache busting
* @param $null
* @param $filename
* @return mixed
* @return bool | string
*/
public function sanitize_file_name( $filename ) {
$callstack = debug_backtrace( DEBUG_BACKTRACE_PROVIDE_OBJECT, 5 );

if ( Utility::isCallStackMatches( $callstack, $this->cache_busting_disable_conditions ) ) {
remove_filter( 'sanitize_file_name', array( "wpCloud\StatelessMedia\Utility", 'randomize_filename' ), 10 );
}
public function maybe_skip_cache_busting( $null, $filename ) {
$callstack = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 8 );

if ( Utility::isCallStackMatches( $callstack, $this->cache_busting_disable_conditions ) )
return $filename;

return $null;
}

}
Expand Down

0 comments on commit 9f8043d

Please sign in to comment.