Plugin Updates

This commit is contained in:
Tony Volpe
2024-04-02 20:23:21 +00:00
parent 96800520e8
commit 94170ec2c4
1514 changed files with 133309 additions and 105985 deletions

View File

@@ -11,7 +11,6 @@ use Automattic\WooCommerce\Blocks\Templates\SingleProductTemplateCompatibility;
use Automattic\WooCommerce\Blocks\Utils\BlockTemplateUtils;
use Automattic\WooCommerce\Blocks\Templates\OrderConfirmationTemplate;
use Automattic\WooCommerce\Blocks\Templates\SingleProductTemplate;
use Automattic\WooCommerce\Blocks\Utils\BlockTemplateMigrationUtils;
/**
* BlockTypesController class.
@@ -59,6 +58,7 @@ class BlockTemplatesController {
add_action( 'template_redirect', array( $this, 'render_block_template' ) );
add_filter( 'pre_get_block_template', array( $this, 'get_block_template_fallback' ), 10, 3 );
add_filter( 'pre_get_block_file_template', array( $this, 'get_block_file_template' ), 10, 3 );
add_filter( 'get_block_template', array( $this, 'add_block_template_details' ), 10, 1 );
add_filter( 'get_block_templates', array( $this, 'add_block_templates' ), 10, 3 );
add_filter( 'current_theme_supports-block-templates', array( $this, 'remove_block_template_support_for_shop_page' ) );
add_filter( 'taxonomy_template_hierarchy', array( $this, 'add_archive_product_to_eligible_for_fallback_templates' ), 10, 1 );
@@ -66,8 +66,6 @@ class BlockTemplatesController {
add_action( 'after_switch_theme', array( $this, 'check_should_use_blockified_product_grid_templates' ), 10, 2 );
if ( wc_current_theme_is_fse_theme() ) {
add_action( 'init', array( $this, 'maybe_migrate_content' ) );
// By default, the Template Part Block only supports template parts that are in the current theme directory.
// This render_callback wrapper allows us to add support for plugin-housed template parts.
add_filter(
@@ -162,7 +160,7 @@ class BlockTemplatesController {
*/
public function render_woocommerce_template_part( $attributes ) {
if ( isset( $attributes['theme'] ) && 'woocommerce/woocommerce' === $attributes['theme'] ) {
$template_part = BlockTemplateUtils::get_block_template( $attributes['theme'] . '//' . $attributes['slug'], 'wp_template_part' );
$template_part = get_block_template( $attributes['theme'] . '//' . $attributes['slug'], 'wp_template_part' );
if ( $template_part && ! empty( $template_part->content ) ) {
return do_blocks( $template_part->content );
@@ -317,7 +315,7 @@ class BlockTemplatesController {
if ( BlockTemplateUtils::DEPRECATED_PLUGIN_SLUG === strtolower( $template_id ) ) {
// Because we are using get_block_templates we have to unhook this method to prevent a recursive loop where this filter is applied.
remove_filter( 'pre_get_block_file_template', array( $this, 'get_block_file_template' ), 10, 3 );
$template_with_deprecated_id = BlockTemplateUtils::get_block_template( $id, $template_type );
$template_with_deprecated_id = get_block_template( $id, $template_type );
// Let's hook this method back now that we have used the function.
add_filter( 'pre_get_block_file_template', array( $this, 'get_block_file_template' ), 10, 3 );
@@ -349,6 +347,25 @@ class BlockTemplatesController {
return $template;
}
/**
* Add the template title and description to WooCommerce templates.
*
* @param WP_Block_Template|null $block_template The found block template, or null if there isn't one.
* @return WP_Block_Template|null
*/
public function add_block_template_details( $block_template ) {
if ( ! $block_template ) {
return $block_template;
}
if ( ! BlockTemplateUtils::template_has_title( $block_template ) ) {
$block_template->title = BlockTemplateUtils::get_block_template_title( $block_template->slug );
}
if ( ! $block_template->description ) {
$block_template->description = BlockTemplateUtils::get_block_template_description( $block_template->slug );
}
return $block_template;
}
/**
* Add the block template objects to be used.
*
@@ -365,6 +382,7 @@ class BlockTemplatesController {
$post_type = isset( $query['post_type'] ) ? $query['post_type'] : '';
$slugs = isset( $query['slug__in'] ) ? $query['slug__in'] : array();
$template_files = $this->get_block_templates( $slugs, $template_type );
$theme_slug = wp_get_theme()->get_stylesheet();
// @todo: Add apply_filters to _gutenberg_get_template_files() in Gutenberg to prevent duplication of logic.
foreach ( $template_files as $template_file ) {
@@ -391,14 +409,12 @@ class BlockTemplatesController {
if ( 'custom' !== $template_file->source ) {
$template = BlockTemplateUtils::build_template_result_from_file( $template_file, $template_type );
} else {
$template_file->title = BlockTemplateUtils::get_block_template_title( $template_file->slug );
$template_file->description = BlockTemplateUtils::get_block_template_description( $template_file->slug );
$query_result[] = $template_file;
$query_result[] = $template_file;
continue;
}
$is_not_custom = false === array_search(
wp_get_theme()->get_stylesheet() . '//' . $template_file->slug,
$theme_slug . '//' . $template_file->slug,
array_column( $query_result, 'id' ),
true
);
@@ -416,6 +432,11 @@ class BlockTemplatesController {
// This only affects saved templates that were saved BEFORE a theme template with the same slug was added.
$query_result = BlockTemplateUtils::remove_theme_templates_with_custom_alternative( $query_result );
// There is the chance that the user customized the default template, installed a theme with a custom template
// and customized that one as well. When that happens, duplicates might appear in the list.
// See: https://github.com/woocommerce/woocommerce/issues/42220.
$query_result = BlockTemplateUtils::remove_duplicate_customized_templates( $query_result, $theme_slug );
/**
* WC templates from theme aren't included in `$this->get_block_templates()` but are handled by Gutenberg.
* We need to do additional search through all templates file to update title and description for WC
@@ -453,15 +474,13 @@ class BlockTemplatesController {
}
}
if ( 'theme' === $template->origin && BlockTemplateUtils::template_has_title( $template ) ) {
return $template;
}
if ( $template->title === $template->slug ) {
if ( ! BlockTemplateUtils::template_has_title( $template ) ) {
$template->title = BlockTemplateUtils::get_block_template_title( $template->slug );
}
if ( ! $template->description ) {
$template->description = BlockTemplateUtils::get_block_template_description( $template->slug );
}
return $template;
},
$query_result
@@ -577,9 +596,8 @@ class BlockTemplatesController {
public function get_block_templates( $slugs = array(), $template_type = 'wp_template' ) {
$templates_from_db = BlockTemplateUtils::get_block_templates_from_db( $slugs, $template_type );
$templates_from_woo = $this->get_block_templates_from_woocommerce( $slugs, $templates_from_db, $template_type );
$templates = array_merge( $templates_from_db, $templates_from_woo );
return BlockTemplateUtils::filter_block_templates_by_feature_flag( $templates );
return array_merge( $templates_from_db, $templates_from_woo );
}
/**
@@ -761,22 +779,4 @@ class BlockTemplatesController {
return $post_type_name;
}
/**
* Migrates page content to templates if needed.
*/
public function maybe_migrate_content() {
// Migration should occur on a normal request to ensure every requirement is met.
// We are postponing it if WP is in maintenance mode, installing, WC installing or if the request is part of a WP-CLI command.
if ( wp_is_maintenance_mode() || ! get_option( 'woocommerce_db_version', false ) || Constants::is_defined( 'WP_SETUP_CONFIG' ) || Constants::is_defined( 'WC_INSTALLING' ) || Constants::is_defined( 'WP_CLI' ) ) {
return;
}
if ( ! BlockTemplateMigrationUtils::has_migrated_page( 'cart' ) ) {
BlockTemplateMigrationUtils::migrate_page( 'cart' );
}
if ( ! BlockTemplateMigrationUtils::has_migrated_page( 'checkout' ) ) {
BlockTemplateMigrationUtils::migrate_page( 'checkout' );
}
}
}