Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix phpcs
Browse files Browse the repository at this point in the history
wordpressfan committed Jan 17, 2025
1 parent 271f3cc commit 7c13eb6
Showing 5 changed files with 48 additions and 3 deletions.
7 changes: 7 additions & 0 deletions inc/Engine/Common/Cache/CacheInterface.php
Original file line number Diff line number Diff line change
@@ -33,4 +33,11 @@ public function get_root_path(): string;
* @return string
*/
public function generate_path( string $url ): string;

/**
* Wipes the whole cache directory .
*
* @return bool True on success and false on failure.
*/
public function full_clear(): bool;
}
25 changes: 24 additions & 1 deletion inc/Engine/Common/Cache/FilesystemCache.php
Original file line number Diff line number Diff line change
@@ -103,6 +103,20 @@ public function clear() {
return true;
}

/**
* Clear the whole background-css directory.
*
* @return bool True on success and false on failure.
*/
public function full_clear(): bool {
$base_path = $this->get_base_path();
if ( ! $this->filesystem->exists( $base_path ) ) {
return false;
}
rocket_rrmdir( $base_path, [], $this->filesystem );
return true;
}

/**
* Obtains multiple cache items by their unique keys.
*
@@ -226,11 +240,20 @@ public function is_accessible(): bool {
}

/**
* Get root path from the cache.
* Get root path from the cache (including current blog ID) with trailing slash.
*
* @return string
*/
public function get_root_path(): string {
return $this->get_base_path() . get_current_blog_id() . '/';
}

/**
* Get base path from the cache (/cache/background-css/) with trailing slash.
*
* @return string
*/
private function get_base_path(): string {
return rtrim( _rocket_normalize_path( rocket_get_constant( 'WP_ROCKET_CACHE_ROOT_PATH' ) ) . $this->root_folder, '/' ) . '/';
}
}
2 changes: 1 addition & 1 deletion inc/Engine/Common/ExtractCSS/ServiceProvider.php
Original file line number Diff line number Diff line change
@@ -41,7 +41,7 @@ public function register(): void {
*
* @param string $root Background CSS cache folder.
*/
$root = apply_filters( 'rocket_lazyload_css_cache_root', 'background-css/' . get_current_blog_id() );
$root = apply_filters( 'rocket_lazyload_css_cache_root', 'background-css/' );
$this->getContainer()->add( 'lazyload_css_cache', FilesystemCache::class )
->addArgument( $root );
$this->getContainer()->addShared( 'common_extractcss_subscriber', Subscriber::class );
16 changes: 16 additions & 0 deletions inc/Engine/Media/Lazyload/CSS/Admin/Subscriber.php
Original file line number Diff line number Diff line change
@@ -34,6 +34,7 @@ public static function get_subscribed_events() {
'rocket_meta_boxes_fields' => [ 'add_meta_box', 8 ],
'admin_notices' => 'maybe_add_error_notice',
'rocket_safe_mode_reset_options' => 'add_option_safemode',
'wp_rocket_upgrade' => [ 'clear_background_css_with_upgrade', 10, 2 ],
];
}

@@ -79,4 +80,19 @@ public function add_option_safemode( array $options ) {
$options['lazyload_css_bg_img'] = 0;
return $options;
}

/**
* Upgrade callback.
*
* @param string $new_version Plugin new version.
* @param string $old_version Plugin old version.
* @return void
*/
public function clear_background_css_with_upgrade( $new_version, $old_version ) {

Check warning on line 91 in inc/Engine/Media/Lazyload/CSS/Admin/Subscriber.php

Codacy Production / Codacy Static Code Analysis

inc/Engine/Media/Lazyload/CSS/Admin/Subscriber.php#L91

Avoid unused parameters such as '$new_version'.
if ( version_compare( $old_version, '3.18', '>' ) ) {
return;
}
// Completely clear background-css directory.
$this->cache->full_clear();
}
}
1 change: 0 additions & 1 deletion inc/Engine/Media/Lazyload/CSS/ServiceProvider.php
Original file line number Diff line number Diff line change
@@ -24,7 +24,6 @@ class ServiceProvider extends AbstractServiceProvider {
* @var array
*/
protected $provides = [
'lazyload_css_cache',
'lazyload_css_subscriber',
];

0 comments on commit 7c13eb6

Please sign in to comment.