Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent 'BlockTemplatesController' to be initialized in classic themes which don't support templates nor template parts #46463

Open
Aljullu opened this issue Apr 11, 2024 · 0 comments
Labels
focus: template Issue related to WooCommerce templates. team: Kirigami & Origami

Comments

@Aljullu
Copy link
Contributor

Aljullu commented Apr 11, 2024

Blocked by #46464.

BlockTemplatesController is a class used to handle block templates and templates parts.

While several of its methods check for the theme to support block templates/block templates parts before running, there are several other methods which don't have those checks, which is easy to cause bugs (see #46429 and #46461).

This issue is about try to only initialize BlockTemplatesController when the theme supports block templates or block template parts. So BlockTemplatesController wouldn't be initialized in classic themes at all.

One challenge is that the check_should_use_blockified_product_grid_templates method needs to be run also in classic themes, so it should be moved out of this class:

/**
* Checks the old and current themes and determines if the "wc_blocks_use_blockified_product_grid_block_as_template"
* option need to be updated accordingly.
*
* @param string $old_name Old theme name.
* @param \WP_Theme $old_theme Instance of the old theme.
* @return void
*/
public function check_should_use_blockified_product_grid_templates( $old_name, $old_theme ) {
if ( ! wc_current_theme_is_fse_theme() ) {
update_option( Options::WC_BLOCK_USE_BLOCKIFIED_PRODUCT_GRID_BLOCK_AS_TEMPLATE, wc_bool_to_string( false ) );
return;
}
if ( ! $old_theme->is_block_theme() && wc_current_theme_is_fse_theme() ) {
update_option( Options::WC_BLOCK_USE_BLOCKIFIED_PRODUCT_GRID_BLOCK_AS_TEMPLATE, wc_bool_to_string( true ) );
return;
}
}

@Aljullu Aljullu added focus: template Issue related to WooCommerce templates. team: Kirigami & Origami labels Apr 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
focus: template Issue related to WooCommerce templates. team: Kirigami & Origami
Projects
No open projects
Development

No branches or pull requests

1 participant