diff --git a/src/Domain/Services/Notices.php b/src/Domain/Services/Notices.php index 47324139036..019b9144dc7 100644 --- a/src/Domain/Services/Notices.php +++ b/src/Domain/Services/Notices.php @@ -16,6 +16,17 @@ class Notices { */ private $package; + /** + * Templates used for notices. + * + * @var array + */ + private $notice_templates = array( + 'notices/error.php', + 'notices/notice.php', + 'notices/success.php', + ); + /** * Constructor * @@ -77,20 +88,8 @@ public function add_kses_notice_allowed_tags( $allowed_tags ) { * @return string */ public function get_notices_template( $template, $template_name, $args, $template_path, $default_path ) { - $found_block_template = false; - if ( 'notices/error.php' === $template_name ) { - $template = $this->package->get_path( 'templates/notices/error.php' ); - $found_block_template = true; - } - if ( 'notices/notice.php' === $template_name ) { - $template = $this->package->get_path( 'templates/notices/notice.php' ); - $found_block_template = true; - } - if ( 'notices/success.php' === $template_name ) { - $template = $this->package->get_path( 'templates/notices/success.php' ); - $found_block_template = true; - } - if ( $found_block_template ) { + if ( in_array( $template_name, $this->notice_templates, true ) ) { + $template = $this->package->get_path( 'templates/' . $template_name ); wp_enqueue_style( 'wc-blocks-style' ); } return $template;