Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Align Woo Block template locations with the newest convention
Browse files Browse the repository at this point in the history
While we now support both the old and new conventions for the templates
paths, our own repo should be aligned with the latest convention.

See: #5455
Fixes: #5343
  • Loading branch information
sunyatasattva committed Dec 27, 2021
1 parent bb52a53 commit 92d5129
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 19 deletions.
19 changes: 7 additions & 12 deletions src/BlockTemplatesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,22 @@ class BlockTemplatesController {
private $template_parts_directory;

/**
* Directory name of the block template directory.
* Directory which contains all templates
*
* @var string
*/
const TEMPLATES_DIR_NAME = 'block-templates';

/**
* Directory name of the block template parts directory.
*
* @var string
*/
const TEMPLATE_PARTS_DIR_NAME = 'block-template-parts';
const TEMPLATES_ROOT_DIR = 'templates';

/**
* Constructor.
*/
public function __construct() {
// This feature is gated for WooCommerce versions 6.0.0 and above.
if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '6.0.0', '>=' ) ) {
$this->templates_directory = plugin_dir_path( __DIR__ ) . 'templates/' . self::TEMPLATES_DIR_NAME;
$this->template_parts_directory = plugin_dir_path( __DIR__ ) . 'templates/' . self::TEMPLATE_PARTS_DIR_NAME;
$root_path = plugin_dir_path( __DIR__ ) . self::TEMPLATES_ROOT_DIR . DIRECTORY_SEPARATOR;

$this->templates_directory = $root_path . BlockTemplateUtils::TEMPLATES_DIR_NAME;
$this->template_parts_directory = $root_path . BlockTemplateUtils::TEMPLATE_PARTS_DIR_NAME;
$this->init();
}
}
Expand Down Expand Up @@ -343,7 +338,7 @@ function ( $template ) use ( $template_slug ) {

// If the theme has an archive-product.html template, but not a taxonomy-product_cat.html template let's use the themes archive-product.html template.
if ( BlockTemplateUtils::template_is_eligible_for_product_archive_fallback( $template_slug ) ) {
$template_file = get_stylesheet_directory() . '/' . self::TEMPLATES_DIR_NAME . '/archive-product.html';
$template_file = BlockTemplateUtils::get_theme_template_path( 'archive-product' );
$templates[] = BlockTemplateUtils::create_new_block_template_object( $template_file, $template_type, $template_slug, true );
continue;
}
Expand Down
7 changes: 0 additions & 7 deletions src/Utils/BlockTemplateUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@
* IMPORTANT: These methods have been duplicated from Gutenberg/lib/full-site-editing/block-templates.php as those functions are not for public usage.
*/
class BlockTemplateUtils {
/**
* Directory name of all the templates.
*
* @var string
*/
const TEMPLATES_ROOT_DIR = 'templates';

/**
* Old directory name of the block templates directory.
*
Expand Down

0 comments on commit 92d5129

Please sign in to comment.