Skip to content

Commit

Permalink
[N/A] Fix an issue when embedding GTM
Browse files Browse the repository at this point in the history
  • Loading branch information
bd-viget committed Jan 13, 2025
1 parent 775ddd0 commit ae50532
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions wp-content/mu-plugins/viget-wp/src/classes/Admin/CustomScripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,27 +190,37 @@ function() {

$scripts = ! empty( $_POST[ self::OPTION_NAME ] ) ? $_POST[ self::OPTION_NAME ] : $this->scripts;
$allowed = [
'script' => [
'type' => [],
'src' => [],
'script' => [
'type' => [],
'src' => [],
'async' => [],
'defer' => [],
],
'noscript' => [],
'iframe' => [
'src' => [],
'width' => [],
'iframe' => [
'src' => [],
'width' => [],
'height' => [],
'style' => [],
'style' => [],
],
'#text' => [], // Allow inline script content
'#text' => [], // Allow inline script content
];

$style_filter = function( array $styles ): array {
$styles[] = 'display';
$styles[] = 'visibility';
return $styles;
};

add_filter( 'safe_style_css', $style_filter );

foreach ( $scripts as $key => $script ) {
$script = wp_kses( wp_unslash( $script ), $allowed );
$scripts[ $key ] = html_entity_decode( $script, ENT_QUOTES | ENT_HTML5 );
}

remove_filter( 'safe_style_css', $style_filter );

update_option( self::OPTION_NAME, $scripts );

$this->scripts = $scripts;
Expand Down

0 comments on commit ae50532

Please sign in to comment.