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

[ 広告アラート ][ リファクタリング ] get_alert_content() は中身だけ返すようにして表示・非表示は外で使うように移動 #1133

Merged
merged 2 commits into from
Nov 11, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 15 additions & 18 deletions inc/promotion-alert/package/class-veu-promotion-alert.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -452,7 +446,6 @@ public static function get_alert_content() {
$alert = wp_kses( '<div class="veu_promotion-alert">' . $alert_content . '</div>', $allowed_html );
$alert = str_replace( '<div class="veu_promotion-alert">', '<div class="veu_promotion-alert" data-nosnippet>', $alert );
}
}

// 許可されたHTMLタグで再度サニタイズ
return apply_filters( 'veu_promotion_alert_content', $alert );
Expand All @@ -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;
}
Expand All @@ -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;
}
}

/**
Expand Down
44 changes: 0 additions & 44 deletions tests/test-promotion-alert.php
Original file line number Diff line number Diff line change
Expand Up @@ -422,50 +422,6 @@ public function test_get_alert_content() {
),
'correct' => '<div class="veu_promotion-alert" data-nosnippet><div class="veu_promotion-alert__content--custom">bbbb</div></div>',
),
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',
Expand Down
Loading