Skip to content

Commit

Permalink
Template are revertable if the original file exists
Browse files Browse the repository at this point in the history
  • Loading branch information
Copons committed Nov 24, 2020
1 parent 37246df commit 19951bd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,20 @@ function filter_rest_prepare_add_wp_theme_slug_and_file_based( $response ) {
$file_based = in_array( '_wp_file_based', $wp_theme_slugs, true );
$response->data['file_based'] = $file_based;

$response->data['original_file_exists'] = false;
$template_files = array_unique(
array_merge(
_gutenberg_get_template_paths( get_stylesheet_directory() . DIRECTORY_SEPARATOR . 'block-templates' ),
_gutenberg_get_template_paths( get_template_directory() . DIRECTORY_SEPARATOR . 'block-templates' )
)
);
foreach( $template_files as $template_file ) {
if ( basename( $template_file, '.html' ) === $response->data['slug'] ) {
$response->data['original_file_exists'] = true;
break;
}
}

$theme_slug = array_values(
array_filter(
$wp_theme_slugs,
Expand Down
1 change: 1 addition & 0 deletions packages/edit-site/src/utils/is-template-revertable.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default function isTemplateRevertable( template, currentTheme ) {
'auto-draft' !== template.status &&
/* eslint-disable camelcase */
template?.file_based &&
template?.original_file_exists &&
currentTheme === template?.wp_theme_slug
/* eslint-enable camelcase */
);
Expand Down

0 comments on commit 19951bd

Please sign in to comment.