Skip to content

Commit

Permalink
Set is_custom property on template and remove redundant code (woocomm…
Browse files Browse the repository at this point in the history
  • Loading branch information
tjcafferkey authored and jonny-bull committed Dec 16, 2021
1 parent 2a97ad5 commit 5875d09
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 12 deletions.
1 change: 0 additions & 1 deletion src/BlockTemplatesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ public function get_block_templates() {
}

$new_template_item = array(
'title' => BlockTemplateUtils::convert_slug_to_title( $template_slug ),
'slug' => $template_slug,
'path' => $template_file,
'theme' => get_template_directory(),
Expand Down
14 changes: 3 additions & 11 deletions src/Utils/BlockTemplateUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,9 @@ public static function gutenberg_inject_theme_attribute_in_content( $template_co
* @param array $template_file Theme file.
* @param array $template_type wp_template or wp_template_part.
*
* @return WP_Block_Template Template.
* @return \WP_Block_Template Template.
*/
public static function gutenberg_build_template_result_from_file( $template_file, $template_type ) {
$default_template_types = function_exists( 'gutenberg_get_default_template_types' ) ? gutenberg_get_default_template_types() : array();
// phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
$template_content = file_get_contents( $template_file['path'] );
$theme = wp_get_theme()->get_stylesheet();
Expand All @@ -98,15 +97,8 @@ public static function gutenberg_build_template_result_from_file( $template_file
$template->title = ! empty( $template_file['title'] ) ? $template_file['title'] : $template_file['slug'];
$template->status = 'publish';
$template->has_theme_file = true;

if ( 'wp_template' === $template_type && isset( $default_template_types[ $template_file['slug'] ] ) ) {
$template->description = $default_template_types[ $template_file['slug'] ]['description'];
$template->title = $default_template_types[ $template_file['slug'] ]['title'];
}

if ( 'wp_template_part' === $template_type && isset( $template_file['area'] ) ) {
$template->area = $template_file['area'];
}
$template->is_custom = false; // Templates loaded from the filesystem aren't custom, ones that have been edited and loaded from the DB are.
$template->title = self::convert_slug_to_title( $template_file['slug'] );

return $template;
}
Expand Down

0 comments on commit 5875d09

Please sign in to comment.