-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Develop anton #443
Develop anton #443
Changes from 4 commits
a93638a
3c7c673
3099b30
ee9f9a5
9f8043d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,9 +16,32 @@ class Divi extends ICompatibility { | |
protected $id = 'divi'; | ||
protected $title = 'Divi'; | ||
protected $constant = 'WP_STATELESS_COMPATIBILITY_DIVI'; | ||
protected $description = 'Ensures compatibility with Divi Builder Export.'; | ||
protected $description = 'Ensures compatibility with Divi theme.'; | ||
protected $theme_name = 'Divi'; | ||
|
||
/** | ||
* Cache Busting call stack conditions to disable. | ||
* Fixing the issue with multiple cache files being created on each page load. | ||
* @see https://github.com/wpCloud/wp-stateless/issues/430 | ||
* @var array | ||
*/ | ||
private $cache_busting_disable_conditions = array( | ||
array( | ||
'stack_level' => 4, | ||
'function' => '__construct', | ||
'class' => 'ET_Core_PageResource' | ||
), | ||
array( | ||
'stack_level' => 4, | ||
'function' => 'get_cache_filename', | ||
'class' => 'ET_Builder_Element' | ||
) | ||
); | ||
|
||
/** | ||
* Initialize compatibility module | ||
* @param $sm | ||
*/ | ||
public function module_init($sm){ | ||
// exclude randomize_filename from export | ||
if( | ||
|
@@ -29,7 +52,25 @@ 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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could have used There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I'll check that filter. But don't understand now what exactly will short-circuit. Can you give an example? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I see now what you mean short-circuit. Will implement using that filter, thanks. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @alimuzzaman I think there is some bug in this line https://github.com/wpCloud/wp-stateless/blob/a93638abe0d2ae5013e0c7f6f7155e8e101c0c33/lib/classes/class-utility.php#L80 It should return Can you confirm this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, for the confusion. you should return unmodified $filename from the filter, not true. Then $return will become $filename. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Ok, makes sense. Better to keep it as is. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will add documentation in |
||
} | ||
|
||
/** | ||
* 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. | ||
* @param $filename | ||
* @return mixed | ||
*/ | ||
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 ); | ||
} | ||
|
||
return $filename; | ||
} | ||
|
||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool