Wp-rocket: Entire cache is cleared when a new image is uploaded to a draft

Created on 26 Apr 2018  路  2Comments  路  Source: wp-media/wp-rocket

When a new image is added to a draft post / page, WP Rocket deletes the entire cache.

Comes down to:

https://github.com/wp-media/wp-rocket/blob/e24f6f9064cbcdaa007512f3464cf53c8e2c67dc/inc/common/purge.php#L178-L183

For a draft get_permalink returns http://example.com/?p=1430
Filtering the url here with rocket_clean_files_users() here
then returns the path of the entire cache folder here:

https://github.com/wp-media/wp-rocket/blob/e24f6f9064cbcdaa007512f3464cf53c8e2c67dc/inc/functions/files.php#L503

And thus we have the spice mix for an interesting edge case.

Thanks to @girlie and the sheer luck that prompted her to test this on a draft instead of a published post on her test site and also for making it available for me to test.

Almost missed the main main here, thanks to @Tabrisrp for all the advice, pointers and tips and debugging company.

low bug

Most helpful comment

A hot-fix: after line 56 here: https://github.com/wp-media/wp-rocket/blob/e24f6f9064cbcdaa007512f3464cf53c8e2c67dc/inc/common/purge.php#L53-L56

Add:

// Hotfix for #968
if ( get_post_type( $post_id ) == 'attachment' ) {
    return;
}

So that it looks like so: http://snippi.com/s/if5eq20

All 2 comments

A hot-fix: after line 56 here: https://github.com/wp-media/wp-rocket/blob/e24f6f9064cbcdaa007512f3464cf53c8e2c67dc/inc/common/purge.php#L53-L56

Add:

// Hotfix for #968
if ( get_post_type( $post_id ) == 'attachment' ) {
    return;
}

So that it looks like so: http://snippi.com/s/if5eq20

Was this page helpful?
0 / 5 - 0 ratings