Skip to content

Commit

Permalink
Allow block notice templates in classic themes
Browse files Browse the repository at this point in the history
  • Loading branch information
nielslange committed Feb 27, 2024
1 parent a668cf9 commit c8b66b0
Show file tree
Hide file tree
Showing 25 changed files with 424 additions and 85 deletions.
Expand Up @@ -7,9 +7,13 @@ 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
wp theme delete storefront-child__classic-notices
wp theme delete twentytwentyfour-child__block-notices
wp theme delete twentytwentyfour-child__classic-notices

# 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.zip"
wp theme install "$themes_dir/storefront-child__classic-notices.zip"
wp theme install "$themes_dir/twentytwentyfour-child__block-notices.zip"
wp theme install "$themes_dir/twentytwentyfour-child__classic-notices.zip"
7 changes: 6 additions & 1 deletion plugins/woocommerce-blocks/tests/e2e/bin/test-env-setup.sh
Expand Up @@ -9,7 +9,12 @@ 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"
"storefront-child__classic-notices"
"twentytwentyfour-child__block-notices"
"twentytwentyfour-child__classic-notices"
)
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,4 @@
/*
Theme Name: Storefront Child (Block Notices)
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)
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,4 @@
/*
Theme Name: Twenty Twenty-Four Child (Block Notices)
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)
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; ?>

0 comments on commit c8b66b0

Please sign in to comment.