Skip to content

Commit

Permalink
chore:added ignore comments for phpcs
Browse files Browse the repository at this point in the history
  • Loading branch information
yssambare12 committed Apr 22, 2024
1 parent c30645b commit 58a9e6e
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion admin/dashboard/includes/class-bsf-custom-fonts-menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,10 @@ public function sanitize_svg( $original_content ) {

// Create DOMDocument instance.
$dom = new DOMDocument();
// phpcs:disable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
$dom->formatOutput = false;
$dom->preserveWhiteSpace = false;
// phpcs:enable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
$dom->strictErrorChecking = false;

$open_svg = ! ! $content ? $dom->loadXML( $content ) : false;
Expand All @@ -319,8 +321,10 @@ public function sanitize_svg( $original_content ) {
}

// Strip Doctype.
// phpcs:disable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
foreach ( $dom->childNodes as $child ) {
if ( XML_DOCUMENT_TYPE_NODE === $child->nodeType && ! ! $child->parentNode ) {
// phpcs:enable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
$child->parentNode->removeChild( $child );
}
}
Expand Down Expand Up @@ -369,12 +373,15 @@ public function sanitize_svg( $original_content ) {
}
}

// Export sanitized SVG to string.
// phpcs:disable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
$sanitized = $dom->saveXML( $dom->documentElement, LIBXML_NOEMPTYTAG );
// phpcs:enable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase

// Restore defaults.
if ( $php_version_under_eight && isset( $libxml_disable_entity_loader ) ) {
// phpcs:disable Generic.PHP.DeprecatedFunctions.Deprecated
libxml_disable_entity_loader( $libxml_disable_entity_loader );
// phpcs:enable Generic.PHP.DeprecatedFunctions.Deprecated
}
libxml_use_internal_errors( $libxml_use_internal_errors );

Expand Down Expand Up @@ -407,7 +414,9 @@ public function update_mime_types( $defaults, $file, $filename ) {
// Perform SVG sanitization using the sanitize_svg function.
$svg_content = file_get_contents( $file ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
$sanitized_svg_content = $this->sanitize_svg( $svg_content );
// phpcs:disable WordPress.WP.AlternativeFunctions.file_system_read_file_put_contents
file_put_contents( $file, $sanitized_svg_content );
// phpcs:enable WordPress.WP.AlternativeFunctions.file_system_read_file_put_contents

// Update mime type and extension.
$defaults['type'] = 'image/svg+xml';
Expand Down

0 comments on commit 58a9e6e

Please sign in to comment.