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

[ CTAブロック ] ホワイトリストのURLのみiframeがエスケープされてしまうのを修正しました #1165

Merged
merged 18 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from 7 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
50 changes: 49 additions & 1 deletion inc/call-to-action/package/block/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,5 +273,53 @@ function veu_cta_block_callback( $attributes, $content ) {
}
}

return wp_kses_post( $content );
return veu_cta_block_safe_kses_post( $content );
}

// ksesから特定のiframeを除外
function veu_allow_custom_iframes( $tags, $context ) {
if ( $context ) {
$tags['iframe'] = array(
'src' => true,
'width' => true,
'height' => true,
'style' => true,
'allowfullscreen' => true,
'loading' => true,
'sandbox' => true,
);
}
return $tags;
}

function veu_cta_block_safe_kses_post( $content ) {
$allowed_iframe_patterns = array(
'/https:\/\/(www\.)?google\.com\//i', // Google Maps
'/https:\/\/(www\.)?youtube\.com\//i', // YouTube
'/https:\/\/www\.openstreetmap\.org\//i', // OpenStreetMap
'/https:\/\/player\.vimeo\.com\//i', // Vimeo
);

preg_match_all( '/<iframe.*?src=["\'](.*?)["\'].*?>.*?<\/iframe>/i', $content, $matches );

$allowed_iframes = array();

foreach ( $matches[1] as $index => $iframe_src ) {
foreach ( $allowed_iframe_patterns as $pattern ) {
if ( preg_match( $pattern, $iframe_src ) ) {
$allowed_iframes[ $matches[0][ $index ] ] = $matches[0][ $index ]; // 元の `iframe` タグを保存
break;
}
}
}

add_filter( 'wp_kses_allowed_html', 'veu_allow_custom_iframes', 10, 2 );
$content = wp_kses_post( $content );
remove_filter( 'wp_kses_allowed_html', 'veu_allow_custom_iframes', 10, 2 );

foreach ( $allowed_iframes as $original_iframe ) {
$content = str_replace( '[iframe-placeholder]', $original_iframe, $content );
}

return $content;
}
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ e.g.

== Changelog ==

[ Bug fix ][ CTA ] Fixed iframes escaping only whitelisted URLs
[ Design Bug Fix ][ Share button ]Resolved an issue where `gap` in the `.veu_socialSet` component was not applying proper spacing between elements.
[ Specification change ] Fixed the zoom-out toggle not always displaying in the editor toolbar (updated blocks.json API version from 2 to 3).

Expand Down
Loading