diff --git a/inc/cloudfront_media_purge/namespace.php b/inc/cloudfront_media_purge/namespace.php index 621015d2..fb4171ed 100644 --- a/inc/cloudfront_media_purge/namespace.php +++ b/inc/cloudfront_media_purge/namespace.php @@ -31,7 +31,8 @@ function purge_media_file_cache( int $media_id ) { $upload_path = wp_parse_url( $upload_url, PHP_URL_PATH ); $upload_path_info = pathinfo( $upload_path ); $items = []; - $items[] = $upload_path_info['dirname'] . '/' . $upload_path_info['filename'] . '*'; + // Make sure the image filename is URL encoded, else CloudFront will not be able to purge it. + $items[] = $upload_path_info['dirname'] . '/' . urlencode( $upload_path_info['filename'] ) . '*'; if ( function_exists( 'tachyon_url' ) ) { $tachyon_url = tachyon_url( $upload_url ); $tachyon_path = wp_parse_url( $tachyon_url, PHP_URL_PATH );