Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
DRY get_notices_template
Browse files Browse the repository at this point in the history
  • Loading branch information
mikejolley committed Mar 21, 2023
1 parent ac55811 commit 63961f9
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions src/Domain/Services/Notices.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 63961f9

Please sign in to comment.