From ce86f26b5d050466dd0299e2b544dcaa6c4b5cbd Mon Sep 17 00:00:00 2001 From: kurudrive Date: Mon, 11 Nov 2024 18:41:41 +0900 Subject: [PATCH] =?UTF-8?q?[=20=E5=BA=83=E5=91=8A=E3=82=A2=E3=83=A9?= =?UTF-8?q?=E3=83=BC=E3=83=88=20][=20=E3=83=AA=E3=83=95=E3=82=A1=E3=82=AF?= =?UTF-8?q?=E3=82=BF=E3=83=AA=E3=83=B3=E3=82=B0=20]=20=09get=5Falert=5Fcon?= =?UTF-8?q?tent()=20=E3=81=AF=E4=B8=AD=E8=BA=AB=E3=81=A0=E3=81=91=E8=BF=94?= =?UTF-8?q?=E3=81=99=E3=82=88=E3=81=86=E3=81=AB=E3=81=97=E3=81=A6=E8=A1=A8?= =?UTF-8?q?=E7=A4=BA=E9=9D=9E=E8=A1=A8=E7=A4=BA=E3=81=AF=E5=A4=96=E3=81=A7?= =?UTF-8?q?=E4=BD=BF=E3=81=86=E3=82=88=E3=81=86=E3=81=AB=E7=A7=BB=E5=8B=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../package/class-veu-promotion-alert.php | 33 +++++++------- tests/test-promotion-alert.php | 44 ------------------- 2 files changed, 15 insertions(+), 62 deletions(-) diff --git a/inc/promotion-alert/package/class-veu-promotion-alert.php b/inc/promotion-alert/package/class-veu-promotion-alert.php index bfc497b8..5460872d 100644 --- a/inc/promotion-alert/package/class-veu-promotion-alert.php +++ b/inc/promotion-alert/package/class-veu-promotion-alert.php @@ -423,12 +423,6 @@ public static function get_alert_content() { $alert = ''; $alert_content = ''; - // 表示条件を判定 - $display = self::is_display( get_the_ID() ); - - // 表示条件が true の場合はアラートを表示 - if ( ! empty( $display ) ) { - // オプションを取得 $options = self::get_options(); @@ -452,7 +446,6 @@ public static function get_alert_content() { $alert = wp_kses( '
' . $alert_content . '
', $allowed_html ); $alert = str_replace( '
', '
', $alert ); } - } // 許可されたHTMLタグで再度サニタイズ return apply_filters( 'veu_promotion_alert_content', $alert ); @@ -465,11 +458,12 @@ public static function get_alert_content() { */ public static function display_alert_filter( $content ) { - // アラートを取得 - $alert = self::get_alert_content(); - - // 文頭にアラートを追加 - $content = $alert . $content; + if ( self::is_display( get_the_ID() ) ){ + // アラートを取得 + $alert = self::get_alert_content(); + // 文頭にアラートを追加 + $content = $alert . $content; + } return $content; } @@ -479,12 +473,15 @@ public static function display_alert_filter( $content ) { */ public static function display_alert_action() { - // アラートを取得 - $alert = self::get_alert_content(); - // 許可されたHTMLタグ - $allowed_html = self::kses_allowed(); - - echo wp_kses( $alert, $allowed_html ); + if ( self::is_display( get_the_ID() ) ){ + // アラートを取得 + $alert = self::get_alert_content(); + // 許可されたHTMLタグ + $allowed_html = self::kses_allowed(); + echo wp_kses( $alert, $allowed_html ); + } else { + return; + } } /** diff --git a/tests/test-promotion-alert.php b/tests/test-promotion-alert.php index 8624c528..6a0d1f7f 100644 --- a/tests/test-promotion-alert.php +++ b/tests/test-promotion-alert.php @@ -422,50 +422,6 @@ public function test_get_alert_content() { ), 'correct' => '
bbbb
', ), - array( - 'name' => 'No text and content / display:hide', - 'options' => array( - 'alert-text' => '', - 'alert-content' => '', - 'alert-display' => array( - 'post' => 'hide', - ), - ), - 'correct' => '', - ), - array( - 'name' => 'No content / display:hide', - 'options' => array( - 'alert-text' => 'aaaa', - 'alert-content' => '', - 'alert-display' => array( - 'post' => 'hide', - ), - ), - 'correct' => '', - ), - array( - 'name' => 'No text / display:hide', - 'options' => array( - 'alert-text' => '', - 'alert-content' => 'bbbb', - 'alert-display' => array( - 'post' => 'hide', - ), - ), - 'correct' => '', - ), - array( - 'name' => 'Normal text and content / display:hide', - 'options' => array( - 'alert-text' => 'aaaa', - 'alert-content' => 'bbbb', - 'alert-display' => array( - 'post' => 'hide', - ), - ), - 'correct' => '', - ), // XSS属性の削除をテスト array( 'name' => 'XSS content',