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

Allow usage of block notice templates when using classic themes #45164

Merged
merged 9 commits into from Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 0 additions & 3 deletions .gitignore
Expand Up @@ -37,9 +37,6 @@ npm-debug.log
*.swp
*.zip

# Allow theme *.zip files for testing purposes
!plugins/woocommerce-blocks/tests/e2e/bin/themes/*.zip

# Built packages
build/
build-module/
Expand Down
Expand Up @@ -7,9 +7,17 @@ script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
themes_dir="$script_dir/../../themes"

# Delete the child themes if they already exist.
wp theme delete storefront-child
wp theme delete twentytwentyfour-child
wp theme delete storefront-child__block-notices-filter
wp theme delete storefront-child__block-notices-template
wp theme delete storefront-child__classic-notices-template
wp theme delete twentytwentyfour-child__block-notices-filter
wp theme delete twentytwentyfour-child__block-notices-template
wp theme delete twentytwentyfour-child__classic-notices-template

# Install the child themes.
wp theme install "$themes_dir/storefront-child.zip"
wp theme install "$themes_dir/twentytwentyfour-child.zip"
wp theme install "$themes_dir/storefront-child__block-notices-filter.zip"
wp theme install "$themes_dir/storefront-child__block-notices-template.zip"
wp theme install "$themes_dir/storefront-child__classic-notices-template.zip"
wp theme install "$themes_dir/twentytwentyfour-child__block-notices-filter.zip"
wp theme install "$themes_dir/twentytwentyfour-child__block-notices-template.zip"
wp theme install "$themes_dir/twentytwentyfour-child__classic-notices-template.zip"
9 changes: 8 additions & 1 deletion plugins/woocommerce-blocks/tests/e2e/bin/test-env-setup.sh
Expand Up @@ -9,7 +9,14 @@ relative_path=${script_dir#$head_dir/}
# Generate the child themes zip files before running the tests.
# By doing so, we ensure that the zip files are up-to-date.
themes_dir="$script_dir/themes"
themes=("storefront-child" "twentytwentyfour-child")
themes=(
"storefront-child__block-notices-filter"
"storefront-child__block-notices-template"
"storefront-child__classic-notices-template"
"twentytwentyfour-child__block-notices-filter"
"twentytwentyfour-child__block-notices-template"
"twentytwentyfour-child__classic-notices-template"
)
for theme in "${themes[@]}"; do
# Define the path to the theme directory and the zip file.
theme_dir="$themes_dir/$theme"
Expand Down

This file was deleted.

@@ -0,0 +1,3 @@
<?php

add_filter( 'woocommerce_use_block_notices_in_classic_theme', '__return_true' );
nielslange marked this conversation as resolved.
Show resolved Hide resolved
@@ -0,0 +1,4 @@
/*
Theme Name: Storefront Child (Block Notices by filter)
Template: storefront
*/
@@ -0,0 +1,4 @@
/*
Theme Name: Storefront Child (Block Notices by template)
Template: storefront
*/
Expand Up @@ -37,13 +37,13 @@
<ul>
<?php foreach ( $notices as $notice ) : ?>
<li<?php echo wc_get_notice_data_attr( $notice ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
BLOCK ERROR NOTICE - <?php echo wc_kses_notice( $notice['notice'] ); ?>
BLOCK ERROR NOTICE: <?php echo wc_kses_notice( $notice['notice'] ); ?>
</li>
<?php endforeach; ?>
</ul>
<?php
} else {
echo 'BLOCK ERROR NOTICE - ' . wc_kses_notice( $notices[0]['notice'] );
echo 'BLOCK ERROR NOTICE: ' . wc_kses_notice( $notices[0]['notice'] );
}
?>
</div>
Expand Down
Expand Up @@ -31,7 +31,7 @@
<path d="M12 3.2c-4.8 0-8.8 3.9-8.8 8.8 0 4.8 3.9 8.8 8.8 8.8 4.8 0 8.8-3.9 8.8-8.8 0-4.8-4-8.8-8.8-8.8zm0 16c-4 0-7.2-3.3-7.2-7.2C4.8 8 8 4.8 12 4.8s7.2 3.3 7.2 7.2c0 4-3.2 7.2-7.2 7.2zM11 17h2v-6h-2v6zm0-8h2V7h-2v2z"></path>
</svg>
<div class="wc-block-components-notice-banner__content">
BLOCK INFO NOTICE - <?php echo wc_kses_notice( $notice['notice'] ); ?>
BLOCK INFO NOTICE: <?php echo wc_kses_notice( $notice['notice'] ); ?>
</div>
</div>
<?php endforeach; ?>
Expand Up @@ -31,7 +31,7 @@
<path d="M16.7 7.1l-6.3 8.5-3.3-2.5-.9 1.2 4.5 3.4L17.9 8z"></path>
</svg>
<div class="wc-block-components-notice-banner__content">
BLOCK SUCCESS NOTICE - <?php echo wc_kses_notice( $notice['notice'] ); ?>
BLOCK SUCCESS NOTICE: <?php echo wc_kses_notice( $notice['notice'] ); ?>
</div>
</div>
<?php endforeach; ?>
@@ -0,0 +1,4 @@
/*
Theme Name: Storefront Child (Classic Notices by template)
Template: storefront
*/
Expand Up @@ -28,7 +28,7 @@
<ul class="woocommerce-error" role="alert">
<?php foreach ( $notices as $notice ) : ?>
<li<?php echo wc_get_notice_data_attr( $notice ); ?>>
CLASSIC ERROR NOTICE - <?php echo wc_kses_notice( $notice['notice'] ); ?>
CLASSIC ERROR NOTICE: <?php echo wc_kses_notice( $notice['notice'] ); ?>
</li>
<?php endforeach; ?>
</ul>
Expand Up @@ -27,6 +27,6 @@

<?php foreach ( $notices as $notice ) : ?>
<div class="woocommerce-info"<?php echo wc_get_notice_data_attr( $notice ); ?>>
CLASSIC INFO NOTICE - <?php echo wc_kses_notice( $notice['notice'] ); ?>
CLASSIC INFO NOTICE: <?php echo wc_kses_notice( $notice['notice'] ); ?>
</div>
<?php endforeach; ?>
Expand Up @@ -27,6 +27,6 @@

<?php foreach ( $notices as $notice ) : ?>
<div class="woocommerce-message"<?php echo wc_get_notice_data_attr( $notice ); ?> role="alert">
CLASSIC SUCCESS NOTICE - <?php echo wc_kses_notice( $notice['notice'] ); ?>
CLASSIC SUCCESS NOTICE: <?php echo wc_kses_notice( $notice['notice'] ); ?>
</div>
<?php endforeach; ?>

This file was deleted.

@@ -0,0 +1,3 @@
<?php

add_filter( 'woocommerce_use_block_notices_in_classic_theme', '__return_false' );
nielslange marked this conversation as resolved.
Show resolved Hide resolved
@@ -0,0 +1,4 @@
/*
Theme Name: Twenty Twenty-Four Child (Block Notices by filter)
Template: twentytwentyfour
*/
@@ -0,0 +1,4 @@
/*
Theme Name: Twenty Twenty-Four Child (Block Notices by template)
Template: twentytwentyfour
*/
@@ -0,0 +1,51 @@
<?php
/**
* Show error messages
*
* This template can be overridden by copying it to yourtheme/woocommerce/notices/error.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
* the readme will list any important changes.
*
* @see https://docs.woocommerce.com/document/template-structure/
* @package WooCommerce\Templates
* @version 8.5.0
*/

if ( ! defined( 'ABSPATH' ) ) {
exit;
}

if ( empty( $notices ) || ! is_array( $notices ) ) {
return;
}

$multiple = count( $notices ) > 1;

?>

<div class="wc-block-components-notice-banner is-error" role="alert" <?php echo $multiple ? '' : wc_get_notice_data_attr( $notices[0] ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" aria-hidden="true" focusable="false">
<path d="M12 3.2c-4.8 0-8.8 3.9-8.8 8.8 0 4.8 3.9 8.8 8.8 8.8 4.8 0 8.8-3.9 8.8-8.8 0-4.8-4-8.8-8.8-8.8zm0 16c-4 0-7.2-3.3-7.2-7.2C4.8 8 8 4.8 12 4.8s7.2 3.3 7.2 7.2c0 4-3.2 7.2-7.2 7.2zM11 17h2v-6h-2v6zm0-8h2V7h-2v2z"></path>
</svg>
<div class="wc-block-components-notice-banner__content">
<?php if ( $multiple ) { ?>
<p class="wc-block-components-notice-banner__summary"><?php esc_html_e( 'The following problems were found:', 'woocommerce' ); ?></p>
<ul>
<?php foreach ( $notices as $notice ) : ?>
<li<?php echo wc_get_notice_data_attr( $notice ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
BLOCK ERROR NOTICE: <?php echo wc_kses_notice( $notice['notice'] ); ?>
</li>
<?php endforeach; ?>
</ul>
<?php
} else {
echo 'BLOCK ERROR NOTICE: ' . wc_kses_notice( $notices[0]['notice'] );
}
?>
</div>
</div>
<?php
@@ -0,0 +1,37 @@
<?php
/**
* Show info messages
*
* This template can be overridden by copying it to yourtheme/woocommerce/notices/notice.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
* the readme will list any important changes.
*
* @see https://docs.woocommerce.com/document/template-structure/
* @package WooCommerce\Templates
* @version 8.5.0
*/

if ( ! defined( 'ABSPATH' ) ) {
exit;
}

if ( ! $notices ) {
return;
}

?>

<?php foreach ( $notices as $notice ) : ?>
<div class="wc-block-components-notice-banner is-info"<?php echo wc_get_notice_data_attr( $notice ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> role="alert">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" aria-hidden="true" focusable="false">
<path d="M12 3.2c-4.8 0-8.8 3.9-8.8 8.8 0 4.8 3.9 8.8 8.8 8.8 4.8 0 8.8-3.9 8.8-8.8 0-4.8-4-8.8-8.8-8.8zm0 16c-4 0-7.2-3.3-7.2-7.2C4.8 8 8 4.8 12 4.8s7.2 3.3 7.2 7.2c0 4-3.2 7.2-7.2 7.2zM11 17h2v-6h-2v6zm0-8h2V7h-2v2z"></path>
</svg>
<div class="wc-block-components-notice-banner__content">
BLOCK INFO NOTICE: <?php echo wc_kses_notice( $notice['notice'] ); ?>
</div>
</div>
<?php endforeach; ?>
@@ -0,0 +1,37 @@
<?php
/**
* Show success messages
*
* This template can be overridden by copying it to yourtheme/woocommerce/notices/success.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
* the readme will list any important changes.
*
* @see https://docs.woocommerce.com/document/template-structure/
* @package WooCommerce\Templates
* @version 8.5.0
*/

if ( ! defined( 'ABSPATH' ) ) {
exit;
}

if ( ! $notices ) {
return;
}

?>

<?php foreach ( $notices as $notice ) : ?>
<div class="wc-block-components-notice-banner is-success"<?php echo wc_get_notice_data_attr( $notice ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> role="alert">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" aria-hidden="true" focusable="false">
<path d="M16.7 7.1l-6.3 8.5-3.3-2.5-.9 1.2 4.5 3.4L17.9 8z"></path>
</svg>
<div class="wc-block-components-notice-banner__content">
BLOCK SUCCESS NOTICE: <?php echo wc_kses_notice( $notice['notice'] ); ?>
</div>
</div>
<?php endforeach; ?>
@@ -0,0 +1,4 @@
/*
Theme Name: Twenty Twenty-Four Child (Classic Notices by template)
Template: twentytwentyfour
*/
@@ -0,0 +1,34 @@
<?php
/**
* Show error messages
*
* This template can be overridden by copying it to yourtheme/woocommerce/notices/error.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
* the readme will list any important changes.
*
* @see https://woo.com/document/template-structure/
* @package WooCommerce\Templates
* @version 3.9.0
*/

if ( ! defined( 'ABSPATH' ) ) {
exit;
}

if ( ! $notices ) {
return;
}

?>

<ul class="woocommerce-error" role="alert">
<?php foreach ( $notices as $notice ) : ?>
<li<?php echo wc_get_notice_data_attr( $notice ); ?>>
CLASSIC ERROR NOTICE: <?php echo wc_kses_notice( $notice['notice'] ); ?>
</li>
<?php endforeach; ?>
</ul>
@@ -0,0 +1,32 @@
<?php
/**
* Show messages
*
* This template can be overridden by copying it to yourtheme/woocommerce/notices/notice.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
* the readme will list any important changes.
*
* @see https://woo.com/document/template-structure/
* @package WooCommerce\Templates
* @version 3.9.0
*/

if ( ! defined( 'ABSPATH' ) ) {
exit;
}

if ( ! $notices ) {
return;
}

?>

<?php foreach ( $notices as $notice ) : ?>
<div class="woocommerce-info"<?php echo wc_get_notice_data_attr( $notice ); ?>>
CLASSIC INFO NOTICE: <?php echo wc_kses_notice( $notice['notice'] ); ?>
</div>
<?php endforeach; ?>
@@ -0,0 +1,32 @@
<?php
/**
* Show messages
*
* This template can be overridden by copying it to yourtheme/woocommerce/notices/success.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
* the readme will list any important changes.
*
* @see https://woo.com/document/template-structure/
* @package WooCommerce\Templates
* @version 3.9.0
*/

if ( ! defined( 'ABSPATH' ) ) {
exit;
}

if ( ! $notices ) {
return;
}

?>

<?php foreach ( $notices as $notice ) : ?>
<div class="woocommerce-message"<?php echo wc_get_notice_data_attr( $notice ); ?> role="alert">
CLASSIC SUCCESS NOTICE: <?php echo wc_kses_notice( $notice['notice'] ); ?>
</div>
<?php endforeach; ?>