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

Account for classic theme support of template parts #9780

Merged
merged 6 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion src/BlockTemplatesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ public function get_block_file_template( $template, $id, $template_type ) {
* @return array
*/
public function add_block_templates( $query_result, $query, $template_type ) {
if ( ! BlockTemplateUtils::supports_block_templates() ) {
if ( ! BlockTemplateUtils::supports_block_templates( 'wp_template_part' ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we'd benefit from a comment here on why wp_template_part for context.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, after taking another look, I think this should be $template_type instead of wp_template_part. Ie, if we are loading Templates, we want to check if the theme supports templates, not template parts.

I changed it in 1843a9a. Also, I think now the code is self-explanatory, do you agree?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think you're right. I just checked the filter params to be sure it was always going to be one of the two (wp_template_part / wp_template ) and it looks to be the case.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also re-tested and everything works as expected from what I can see unless the E2E tests pick up anything.

return $query_result;
}

Expand Down
2 changes: 1 addition & 1 deletion src/BlockTypes/MiniCart.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ protected function enqueue_data( array $attributes = [] ) {

if (
current_user_can( 'edit_theme_options' ) &&
wc_current_theme_is_fse_theme()
( wc_current_theme_is_fse_theme() || current_theme_supports( 'block-template-parts' ) )
) {
$theme_slug = BlockTemplateUtils::theme_has_template_part( 'mini-cart' ) ? wp_get_theme()->get_stylesheet() : BlockTemplateUtils::PLUGIN_SLUG;

Expand Down
20 changes: 10 additions & 10 deletions src/Utils/BlockTemplateUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -440,25 +440,25 @@ public static function theme_has_template_part( $template_name ) {
/**
* Checks to see if they are using a compatible version of WP, or if not they have a compatible version of the Gutenberg plugin installed.
*
* @param string $template_type Optional. Template type: `wp_template` or `wp_template_part`.
* Default `wp_template`.
* @return boolean
*/
public static function supports_block_templates() {
if (
! wc_current_theme_is_fse_theme() &&
( ! function_exists( 'gutenberg_supports_block_templates' ) || ! gutenberg_supports_block_templates() )
) {
return false;
public static function supports_block_templates( $template_type = 'wp_template' ) {
if ( 'wp_template_part' === $template_type && ( wc_current_theme_is_fse_theme() || current_theme_supports( 'block-template-parts' ) ) ) {
return true;
} elseif ( 'wp_template' === $template_type && wc_current_theme_is_fse_theme() ) {
return true;
}

return true;
return false;
}

/**
* Retrieves a single unified template object using its id.
*
* @param string $id Template unique identifier (example: theme_slug//template_slug).
* @param string $template_type Optional. Template type: `'wp_template'` or '`wp_template_part'`.
* Default `'wp_template'`.
* @param string $template_type Optional. Template type: `wp_template` or 'wp_template_part`.
* Default `wp_template`.
*
* @return WP_Block_Template|null Template.
*/
Expand Down