AI
1 year ago
AIContent
1 year ago
Assets
4 weeks ago
BlockTypes
1 week ago
Domain
2 months ago
Images
1 year ago
Integrations
2 years ago
Patterns
6 months ago
Payments
5 months ago
Registry
2 years ago
SharedStores
2 months ago
Shipping
7 months ago
Templates
2 months ago
Utils
4 weeks ago
Assets.php
2 years ago
AssetsController.php
4 weeks ago
BlockPatterns.php
7 months ago
BlockTemplatesController.php
7 months ago
BlockTemplatesRegistry.php
10 months ago
BlockTypesController.php
4 weeks ago
DependencyDetection.php
5 months ago
InboxNotifications.php
2 years ago
Installer.php
2 months ago
Library.php
2 years ago
Options.php
2 years ago
Package.php
1 year ago
QueryFilters.php
7 months ago
TemplateOptions.php
1 year ago
TemplateOptions.php
43 lines
| 1 | <?php |
| 2 | declare( strict_types = 1 ); |
| 3 | |
| 4 | namespace Automattic\WooCommerce\Blocks; |
| 5 | |
| 6 | use Automattic\WooCommerce\Blocks\Options; |
| 7 | |
| 8 | /** |
| 9 | * TemplateOptions class. |
| 10 | * |
| 11 | * @internal |
| 12 | */ |
| 13 | class TemplateOptions { |
| 14 | |
| 15 | /** |
| 16 | * Initialization method. |
| 17 | */ |
| 18 | public function init() { |
| 19 | add_action( 'after_switch_theme', array( $this, 'check_should_use_blockified_product_grid_templates' ), 10, 2 ); |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * Checks the old and current themes and determines if the "wc_blocks_use_blockified_product_grid_block_as_template" |
| 24 | * option need to be updated accordingly. |
| 25 | * |
| 26 | * @param string $old_name Old theme name. |
| 27 | * @param \WP_Theme $old_theme Instance of the old theme. |
| 28 | * @return void |
| 29 | */ |
| 30 | public function check_should_use_blockified_product_grid_templates( $old_name, $old_theme ) { |
| 31 | if ( ! $old_theme->is_block_theme() && wp_is_block_theme() ) { |
| 32 | $option_name = Options::WC_BLOCK_USE_BLOCKIFIED_PRODUCT_GRID_BLOCK_AS_TEMPLATE; |
| 33 | // We previously stored "yes" or "no" values. This will convert them to true or false. |
| 34 | $option_value = wc_string_to_bool( get_option( $option_name ) ); |
| 35 | |
| 36 | // We don't need to do anything if the option is already set to true. |
| 37 | if ( ! $option_value ) { |
| 38 | update_option( $option_name, true ); |
| 39 | } |
| 40 | } |
| 41 | } |
| 42 | } |
| 43 |