Skip to content
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

Flush cache after saving/creating/exporting themes #654

Merged
merged 2 commits into from
May 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion includes/class-create-block-theme-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ function rest_clone_theme( $request ) {

$response = CBT_Theme_Create::clone_current_theme( $this->sanitize_theme_data( $request->get_params() ) );

wp_cache_flush();

if ( is_wp_error( $response ) ) {
return $response;
}
Expand All @@ -224,6 +226,8 @@ function rest_create_child_theme( $request ) {

$response = CBT_Theme_Create::create_child_theme( $theme, $screenshot );

wp_cache_flush();

if ( is_wp_error( $response ) ) {
return $response;
}
Expand All @@ -240,6 +244,8 @@ function rest_create_variation( $request ) {

$response = CBT_Theme_JSON::add_theme_json_variation_to_local( 'variation', $this->sanitize_theme_data( $request->get_params() ) );

wp_cache_flush();

if ( is_wp_error( $response ) ) {
return $response;
}
Expand All @@ -260,6 +266,8 @@ function rest_create_blank_theme( $request ) {

$response = CBT_Theme_Create::create_blank_theme( $theme, $screenshot );

wp_cache_flush();

if ( is_wp_error( $response ) ) {
return $response;
}
Expand Down Expand Up @@ -320,6 +328,8 @@ function rest_export_cloned_theme( $request ) {

$zip->close();

wp_cache_flush();

header( 'Content-Type: application/zip' );
header( 'Content-Disposition: attachment; filename=' . $theme['slug'] . '.zip' );
header( 'Content-Length: ' . filesize( $filename ) );
Expand Down Expand Up @@ -373,6 +383,8 @@ function rest_export_child_cloned_theme( $request ) {

$zip->close();

wp_cache_flush();
mikachan marked this conversation as resolved.
Show resolved Hide resolved

header( 'Content-Type: application/zip' );
header( 'Content-Disposition: attachment; filename=' . $theme['slug'] . '.zip' );
header( 'Content-Length: ' . filesize( $filename ) );
Expand All @@ -390,7 +402,7 @@ function rest_export_theme( $request ) {
__( 'Unable to create a zip file. ZipArchive not available.', 'create-block-theme' ),
);
}

wp_cache_flush();
$theme_slug = wp_get_theme()->get( 'TextDomain' );

// Create ZIP file in the temporary directory.
Expand All @@ -400,6 +412,7 @@ function rest_export_theme( $request ) {
$zip = CBT_Theme_Zip::copy_theme_to_zip( $zip, null, null );

if ( is_child_theme() ) {
wp_cache_flush();
$zip = CBT_Theme_Zip::add_templates_to_zip( $zip, 'current', $theme_slug );
$theme_json = CBT_Theme_JSON_Resolver::export_theme_data( 'current' );
} else {
Expand All @@ -413,6 +426,8 @@ function rest_export_theme( $request ) {

$zip->close();

wp_cache_flush();

header( 'Content-Type: application/zip' );
header( 'Content-Disposition: attachment; filename=' . $theme_slug . '.zip' );
header( 'Content-Length: ' . filesize( $filename ) );
Expand Down Expand Up @@ -448,6 +463,8 @@ function rest_update_theme( $request ) {
return $response;
}

wp_cache_flush();

return new WP_REST_Response(
array(
'status' => 'SUCCESS',
Expand Down Expand Up @@ -489,6 +506,8 @@ function rest_save_theme( $request ) {
CBT_Theme_Styles::clear_user_styles_customizations();
}

wp_cache_flush();

return new WP_REST_Response(
array(
'status' => 'SUCCESS',
Expand Down
Loading