Skip to content

Commit

Permalink
Fix site header when adding x-frame-options (#3964)
Browse files Browse the repository at this point in the history
  • Loading branch information
johngodley authored Dec 30, 2024
1 parent 103c907 commit e89774a
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions models/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,20 @@ private function normalize( $header ) {

if ( isset( $header['headerSettings'] ) && is_array( $header['headerSettings'] ) ) {
foreach ( $header['headerSettings'] as $key => $setting_value ) {
if ( is_array( $setting_value ) && isset( $setting_value['value'] ) ) {
$settings[ $this->sanitize( sanitize_text_field( $key ) ) ] = $this->sanitize( $setting_value['value'] );
if ( is_array( $setting_value ) ) {
if ( isset( $setting_value['value'] ) ) {
$settings[ $this->sanitize( sanitize_text_field( $key ) ) ] = $this->sanitize( $setting_value['value'] );
} elseif ( isset( $setting_value['choices'] ) ) {
$settings[ $this->sanitize( sanitize_text_field( $key ) ) ] = array_map(
function ( $choice ) {
return [
'label' => $this->sanitize( isset( $choice['label'] ) ? $choice['label'] : '' ),
'value' => $this->sanitize( isset( $choice['value'] ) ? $choice['value'] : '' ),
];
},
$setting_value['choices']
);
}
} else {
$settings[ $this->sanitize( sanitize_text_field( $key ) ) ] = $this->sanitize( $setting_value );
}
Expand Down Expand Up @@ -108,6 +120,10 @@ public function run( $headers ) {
}

private function sanitize( $text ) {
if ( is_array( $text ) ) {
return '';
}

// No new lines
$text = preg_replace( "/[\r\n\t].*?$/s", '', $text );

Expand Down

0 comments on commit e89774a

Please sign in to comment.