Skip to content

Commit

Permalink
Flush cache after creating new themes (#654)
Browse files Browse the repository at this point in the history
* Flush cache after create new themes

* remove duplicated call
  • Loading branch information
matiasbenedetto authored May 30, 2024
1 parent 2b17395 commit 4b1181d
Showing 1 changed file with 20 additions and 1 deletion.
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();

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

0 comments on commit 4b1181d

Please sign in to comment.